Skip to content

Commit

Permalink
Deprecate all BIO_meth_get_*() functions
Browse files Browse the repository at this point in the history
Their use by applications is inherently unsafe.
Fixes openssl#26047

Reviewed-by: Paul Dale <[email protected]>
Reviewed-by: Tom Cosgrove <[email protected]>
(Merged from openssl#26056)
  • Loading branch information
t8m committed Nov 28, 2024
1 parent a64d26a commit 0bba821
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 53 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ OpenSSL 3.5

### Changes between 3.4 and 3.5 [xx XXX xxxx]

* All the BIO_meth_get_*() functions allowing reuse of the internal OpenSSL
BIO method implementations were deprecated. The reuse is unsafe due to
dependency on the code of the internal methods not changing.

*Tomáš Mráz*

* Support DEFAULT keyword and '-' prefix in SSL_CTX_set1_groups_list().
SSL_CTX_set1_groups_list() now supports the DEFAULT keyword which sets the
available groups to the default selection. The '-' prefix allows the calling
Expand Down
20 changes: 20 additions & 0 deletions crypto/bio/bio_meth.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ void BIO_meth_free(BIO_METHOD *biom)
}
}

#ifndef OPENSSL_NO_DEPRECATED_3_5
int (*BIO_meth_get_write(const BIO_METHOD *biom)) (BIO *, const char *, int)
{
return biom->bwrite_old;
Expand All @@ -65,6 +66,7 @@ int (*BIO_meth_get_write_ex(const BIO_METHOD *biom)) (BIO *, const char *, size_
{
return biom->bwrite;
}
#endif

/* Conversion for old style bwrite to new style */
int bwrite_conv(BIO *bio, const char *data, size_t datal, size_t *written)
Expand Down Expand Up @@ -102,6 +104,7 @@ int BIO_meth_set_write_ex(BIO_METHOD *biom,
return 1;
}

#ifndef OPENSSL_NO_DEPRECATED_3_5
int (*BIO_meth_get_read(const BIO_METHOD *biom)) (BIO *, char *, int)
{
return biom->bread_old;
Expand All @@ -111,6 +114,7 @@ int (*BIO_meth_get_read_ex(const BIO_METHOD *biom)) (BIO *, char *, size_t, size
{
return biom->bread;
}
#endif

/* Conversion for old style bread to new style */
int bread_conv(BIO *bio, char *data, size_t datal, size_t *readbytes)
Expand Down Expand Up @@ -148,10 +152,12 @@ int BIO_meth_set_read_ex(BIO_METHOD *biom,
return 1;
}

#ifndef OPENSSL_NO_DEPRECATED_3_5
int (*BIO_meth_get_puts(const BIO_METHOD *biom)) (BIO *, const char *)
{
return biom->bputs;
}
#endif

int BIO_meth_set_puts(BIO_METHOD *biom,
int (*bputs) (BIO *, const char *))
Expand All @@ -160,10 +166,12 @@ int BIO_meth_set_puts(BIO_METHOD *biom,
return 1;
}

#ifndef OPENSSL_NO_DEPRECATED_3_5
int (*BIO_meth_get_gets(const BIO_METHOD *biom)) (BIO *, char *, int)
{
return biom->bgets;
}
#endif

int BIO_meth_set_gets(BIO_METHOD *biom,
int (*bgets) (BIO *, char *, int))
Expand All @@ -172,10 +180,12 @@ int BIO_meth_set_gets(BIO_METHOD *biom,
return 1;
}

#ifndef OPENSSL_NO_DEPRECATED_3_5
long (*BIO_meth_get_ctrl(const BIO_METHOD *biom)) (BIO *, int, long, void *)
{
return biom->ctrl;
}
#endif

int BIO_meth_set_ctrl(BIO_METHOD *biom,
long (*ctrl) (BIO *, int, long, void *))
Expand All @@ -184,32 +194,38 @@ int BIO_meth_set_ctrl(BIO_METHOD *biom,
return 1;
}

#ifndef OPENSSL_NO_DEPRECATED_3_5
int (*BIO_meth_get_create(const BIO_METHOD *biom)) (BIO *)
{
return biom->create;
}
#endif

int BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *))
{
biom->create = create;
return 1;
}

#ifndef OPENSSL_NO_DEPRECATED_3_5
int (*BIO_meth_get_destroy(const BIO_METHOD *biom)) (BIO *)
{
return biom->destroy;
}
#endif

int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *))
{
biom->destroy = destroy;
return 1;
}

#ifndef OPENSSL_NO_DEPRECATED_3_5
long (*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom)) (BIO *, int, BIO_info_cb *)
{
return biom->callback_ctrl;
}
#endif

int BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
long (*callback_ctrl) (BIO *, int,
Expand All @@ -226,9 +242,11 @@ int BIO_meth_set_sendmmsg(BIO_METHOD *biom,
return 1;
}

#ifndef OPENSSL_NO_DEPRECATED_3_5
int (*BIO_meth_get_sendmmsg(const BIO_METHOD *biom))(BIO *, BIO_MSG *, size_t, size_t, uint64_t, size_t *) {
return biom->bsendmmsg;
}
#endif

int BIO_meth_set_recvmmsg(BIO_METHOD *biom,
int (*brecvmmsg) (BIO *, BIO_MSG *, size_t, size_t, uint64_t, size_t *))
Expand All @@ -237,6 +255,8 @@ int BIO_meth_set_recvmmsg(BIO_METHOD *biom,
return 1;
}

#ifndef OPENSSL_NO_DEPRECATED_3_5
int (*BIO_meth_get_recvmmsg(const BIO_METHOD *biom))(BIO *, BIO_MSG *, size_t, size_t, uint64_t, size_t *) {
return biom->brecvmmsg;
}
#endif
68 changes: 46 additions & 22 deletions doc/man3/BIO_meth_new.pod
Original file line number Diff line number Diff line change
Expand Up @@ -22,59 +22,64 @@ BIO_meth_set_recvmmsg, BIO_meth_get_recvmmsg - Routines to build up BIO methods

void BIO_meth_free(BIO_METHOD *biom);

int (*BIO_meth_get_write_ex(const BIO_METHOD *biom))(BIO *, const char *, size_t,
size_t *);
int (*BIO_meth_get_write(const BIO_METHOD *biom))(BIO *, const char *, int);
int BIO_meth_set_write_ex(BIO_METHOD *biom,
int (*bwrite)(BIO *, const char *, size_t, size_t *));
int BIO_meth_set_write(BIO_METHOD *biom,
int (*write)(BIO *, const char *, int));

int (*BIO_meth_get_read_ex(const BIO_METHOD *biom))(BIO *, char *, size_t, size_t *);
int (*BIO_meth_get_read(const BIO_METHOD *biom))(BIO *, char *, int);
int BIO_meth_set_read_ex(BIO_METHOD *biom,
int (*bread)(BIO *, char *, size_t, size_t *));
int BIO_meth_set_read(BIO_METHOD *biom, int (*read)(BIO *, char *, int));

int (*BIO_meth_get_puts(const BIO_METHOD *biom))(BIO *, const char *);
int BIO_meth_set_puts(BIO_METHOD *biom, int (*puts)(BIO *, const char *));

int (*BIO_meth_get_gets(const BIO_METHOD *biom))(BIO *, char *, int);
int BIO_meth_set_gets(BIO_METHOD *biom,
int (*gets)(BIO *, char *, int));

long (*BIO_meth_get_ctrl(const BIO_METHOD *biom))(BIO *, int, long, void *);
int BIO_meth_set_ctrl(BIO_METHOD *biom,
long (*ctrl)(BIO *, int, long, void *));

int (*BIO_meth_get_create(const BIO_METHOD *bion))(BIO *);
int BIO_meth_set_create(BIO_METHOD *biom, int (*create)(BIO *));

int (*BIO_meth_get_destroy(const BIO_METHOD *biom))(BIO *);
int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy)(BIO *));

long (*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom))(BIO *, int, BIO_info_cb *);
int BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
long (*callback_ctrl)(BIO *, int, BIO_info_cb *));

int BIO_meth_set_sendmmsg(BIO_METHOD *biom,
ossl_ssize_t (*f) (BIO *, BIO_MSG *, size_t,
size_t, uint64_t));
int BIO_meth_set_recvmmsg(BIO_METHOD *biom,
ossl_ssize_t (*f) (BIO *, BIO_MSG *, size_t,
size_t, uint64_t));

The following functions have been deprecated since OpenSSL 3.5:

int (*BIO_meth_get_write_ex(const BIO_METHOD *biom))(BIO *, const char *, size_t,
size_t *);
int (*BIO_meth_get_write(const BIO_METHOD *biom))(BIO *, const char *, int);

int (*BIO_meth_get_read_ex(const BIO_METHOD *biom))(BIO *, char *, size_t, size_t *);
int (*BIO_meth_get_read(const BIO_METHOD *biom))(BIO *, char *, int);

int (*BIO_meth_get_puts(const BIO_METHOD *biom))(BIO *, const char *);
int (*BIO_meth_get_gets(const BIO_METHOD *biom))(BIO *, char *, int);

long (*BIO_meth_get_ctrl(const BIO_METHOD *biom))(BIO *, int, long, void *);

int (*BIO_meth_get_create(const BIO_METHOD *bion))(BIO *);
int (*BIO_meth_get_destroy(const BIO_METHOD *biom))(BIO *);

long (*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom))(BIO *, int, BIO_info_cb *);

ossl_ssize_t (*BIO_meth_get_sendmmsg(const BIO_METHOD *biom))(BIO *,
BIO_MSG *,
size_t,
size_t,
uint64_t);
int BIO_meth_set_sendmmsg(BIO_METHOD *biom,
ossl_ssize_t (*f) (BIO *, BIO_MSG *, size_t,
size_t, uint64_t));

ossl_ssize_t (*BIO_meth_get_recvmmsg(const BIO_METHOD *biom))(BIO *,
BIO_MSG *,
size_t,
size_t,
uint64_t);
int BIO_meth_set_recvmmsg(BIO_METHOD *biom,
ossl_ssize_t (*f) (BIO *, BIO_MSG *, size_t,
size_t, uint64_t));


=head1 DESCRIPTION

Expand Down Expand Up @@ -176,13 +181,32 @@ The B<BIO_meth_set> functions return 1 on success or 0 on error.

The B<BIO_meth_get> functions return the corresponding function pointers.

=head1 BUGS

It is not safe to use C<BIO_meth_get_> functions to reuse the B<BIO>
implementation of B<BIO>s implemented by OpenSSL itself with
application-implemented B<BIO>s. Instead either the applications ought to
implement these functions themselves or they should implement a filter BIO.

For more details please see L<https://github.com/openssl/openssl/issues/26047>.

=head1 SEE ALSO

L<bio(7)>, L<BIO_find_type(3)>, L<BIO_ctrl(3)>, L<BIO_read_ex(3)>, L<BIO_new(3)>

=head1 HISTORY

The functions described here were added in OpenSSL 1.1.0.
The functions BIO_meth_get_sendmmsg(), BIO_meth_set_sendmmsg(),
BIO_meth_get_recvmmsg() and BIO_meth_set_recvmmsg() were added in OpenSSL 3.2.

All the other functions described here were added in OpenSSL 1.1.0.

The functions BIO_meth_get_read_ex(), BIO_meth_get_write_ex(),
BIO_meth_get_write(), BIO_meth_get_read(), BIO_meth_get_puts(),
BIO_meth_get_gets(), BIO_meth_get_ctrl(), BIO_meth_get_create(),
BIO_meth_get_destroy(), BIO_meth_get_callback_ctrl(),
BIO_meth_get_sendmmsg() and BIO_meth_get_recvmmsg() are deprecated since
OpenSSL 3.5.

=head1 COPYRIGHT

Expand Down
42 changes: 23 additions & 19 deletions include/openssl/bio.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -942,50 +942,54 @@ ossl_bio__attr__((__format__(ossl_bio__printf__, 3, 0)));

BIO_METHOD *BIO_meth_new(int type, const char *name);
void BIO_meth_free(BIO_METHOD *biom);
int (*BIO_meth_get_write(const BIO_METHOD *biom)) (BIO *, const char *, int);
int (*BIO_meth_get_write_ex(const BIO_METHOD *biom)) (BIO *, const char *, size_t,
size_t *);
int BIO_meth_set_write(BIO_METHOD *biom,
int (*write) (BIO *, const char *, int));
int BIO_meth_set_write_ex(BIO_METHOD *biom,
int (*bwrite) (BIO *, const char *, size_t, size_t *));
int BIO_meth_set_sendmmsg(BIO_METHOD *biom,
int (*f) (BIO *, BIO_MSG *, size_t, size_t,
uint64_t, size_t *));
int (*BIO_meth_get_sendmmsg(const BIO_METHOD *biom))(BIO *, BIO_MSG *,
size_t, size_t,
uint64_t, size_t *);
int (*BIO_meth_get_read(const BIO_METHOD *biom)) (BIO *, char *, int);
int (*BIO_meth_get_read_ex(const BIO_METHOD *biom)) (BIO *, char *, size_t, size_t *);
int BIO_meth_set_read(BIO_METHOD *biom,
int (*read) (BIO *, char *, int));
int BIO_meth_set_read_ex(BIO_METHOD *biom,
int (*bread) (BIO *, char *, size_t, size_t *));
int BIO_meth_set_recvmmsg(BIO_METHOD *biom,
int (*f) (BIO *, BIO_MSG *, size_t, size_t,
uint64_t, size_t *));
int (*BIO_meth_get_recvmmsg(const BIO_METHOD *biom))(BIO *, BIO_MSG *,
size_t, size_t,
uint64_t, size_t *);
int (*BIO_meth_get_puts(const BIO_METHOD *biom)) (BIO *, const char *);
int BIO_meth_set_puts(BIO_METHOD *biom,
int (*puts) (BIO *, const char *));
int (*BIO_meth_get_gets(const BIO_METHOD *biom)) (BIO *, char *, int);
int BIO_meth_set_gets(BIO_METHOD *biom,
int (*ossl_gets) (BIO *, char *, int));
long (*BIO_meth_get_ctrl(const BIO_METHOD *biom)) (BIO *, int, long, void *);
int BIO_meth_set_ctrl(BIO_METHOD *biom,
long (*ctrl) (BIO *, int, long, void *));
int (*BIO_meth_get_create(const BIO_METHOD *bion)) (BIO *);
int BIO_meth_set_create(BIO_METHOD *biom, int (*create) (BIO *));
int (*BIO_meth_get_destroy(const BIO_METHOD *biom)) (BIO *);
int BIO_meth_set_destroy(BIO_METHOD *biom, int (*destroy) (BIO *));
long (*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom))
(BIO *, int, BIO_info_cb *);
int BIO_meth_set_callback_ctrl(BIO_METHOD *biom,
long (*callback_ctrl) (BIO *, int,
BIO_info_cb *));

# ifndef OPENSSL_NO_DEPRECATED_3_5
OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_write(const BIO_METHOD *biom)) (BIO *, const char *,
int);
OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_write_ex(const BIO_METHOD *biom)) (BIO *, const char *,
size_t, size_t *);
OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_sendmmsg(const BIO_METHOD *biom))(BIO *, BIO_MSG *,
size_t, size_t,
uint64_t, size_t *);
OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_read(const BIO_METHOD *biom)) (BIO *, char *, int);
OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_read_ex(const BIO_METHOD *biom)) (BIO *, char *,
size_t, size_t *);
OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_recvmmsg(const BIO_METHOD *biom))(BIO *, BIO_MSG *,
size_t, size_t,
uint64_t, size_t *);
OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_puts(const BIO_METHOD *biom)) (BIO *, const char *);
OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_gets(const BIO_METHOD *biom)) (BIO *, char *, int);
OSSL_DEPRECATEDIN_3_5 long (*BIO_meth_get_ctrl(const BIO_METHOD *biom)) (BIO *, int,
long, void *);
OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_create(const BIO_METHOD *bion)) (BIO *);
OSSL_DEPRECATEDIN_3_5 int (*BIO_meth_get_destroy(const BIO_METHOD *biom)) (BIO *);
OSSL_DEPRECATEDIN_3_5 long (*BIO_meth_get_callback_ctrl(const BIO_METHOD *biom)) (BIO *, int,
BIO_info_cb *);
# endif
# ifdef __cplusplus
}
# endif
Expand Down
11 changes: 11 additions & 0 deletions include/openssl/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,17 @@
# undef OPENSSL_NO_DEPRECATED_1_0_0
# undef OPENSSL_NO_DEPRECATED_0_9_8

# if OPENSSL_API_LEVEL >= 30500
# ifndef OPENSSL_NO_DEPRECATED
# define OSSL_DEPRECATEDIN_3_5 OSSL_DEPRECATED(3.5)
# define OSSL_DEPRECATEDIN_3_5_FOR(msg) OSSL_DEPRECATED_FOR(3.5, msg)
# else
# define OPENSSL_NO_DEPRECATED_3_5
# endif
# else
# define OSSL_DEPRECATEDIN_3_5
# define OSSL_DEPRECATEDIN_3_5_FOR(msg)
# endif
# if OPENSSL_API_LEVEL >= 30400
# ifndef OPENSSL_NO_DEPRECATED
# define OSSL_DEPRECATEDIN_3_4 OSSL_DEPRECATED(3.4)
Expand Down
Loading

0 comments on commit 0bba821

Please sign in to comment.