lib: Add safe_recvmsg
PATCH 1/2 lib: Add safe_recvmsg
Identical to safe_sendmsg except *msg is not const.
--- include/safe_net_fn.h | 3 +++ include/tst_safe_net.h | 3 +++ lib/safe_net.c | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+)
include/safe_net_fn.h +3 -0
@@ -49,6 +49,9 @@ ssize_t safe_sendto(const char *file, const int lineno, char len_strict,ssize_t safe_sendmsg (const char *file,const int lineno,size_t msg_len,int sockfd,const struct msghdr *msg,int flags); +ssize_t safe_recvmsg (const char *file,const int lineno,size_t msg_len, +int sockfd,struct msghdr *msg,int flags); +int safe_bind (const char *file,const int lineno,void (cleanup_fn )(void ),int socket,const struct sockaddr *address,socklen_t address_len);
include/tst_safe_net.h +3 -0
@@ -54,6 +54,9 @@#define SAFE_SENDMSG (msg_len, fd, msg, flags) \ safe_sendmsg(__FILE__, __LINE__, msg_len, fd, msg, flags) +#define SAFE_RECVMSG (msg_len, fd, msg, flags) \ + safe_recvmsg(__FILE__, __LINE__, msg_len, fd, msg, flags) +#define SAFE_BIND (socket, address, address_len) \ safe_bind(__FILE__, __LINE__, NULL, socket, address, \ address_len)
lib/safe_net.c +23 -0
@@ -209,6 +209,29 @@ ssize_t safe_sendmsg(const char *file, const int lineno, size_t len,return rval; } +ssize_t safe_recvmsg (const char *file,const int lineno,size_t len, +int sockfd,struct msghdr *msg,int flags) +{ +ssize_t rval; + + rval =recvmsg (sockfd, msg, flags); + +if (rval ==-1 ) { +tst_brkm (TBROK |TERRNO ,NULL , +"%s:%d: recvmsg(%d, %p, %d) failed" , + file, lineno, sockfd, msg, flags); + } + +if (len && (size_t )rval != len) { +tst_brkm (TBROK ,NULL , +"%s:%d: recvmsg(%d, %p, %d) ret(%zd) != len(%zu)" , + file, lineno, sockfd, msg, flags, rval, len); + } + +return rval; + +} +int safe_bind (const char *file,const int lineno,void (cleanup_fn )(void ),int socket,const struct sockaddr *address,socklen_t address_len)
Signature · 1 line
2.16.2
PATCH 2/2 Add CVE-2017-18075, pcrypt mishandles freeing instances
---
I can not find the original reproducer posted upstream. I assume it was created by syzkaller.
This patch will not display error messages correctly without the previous TRERRNO patch I posted.
runtest/cve | 1 + testcases/cve/.gitignore | 1 + testcases/cve/cve-2017-18075.c | 201 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 203 insertions(+) create mode 100644 testcases/cve/cve-2017-18075.c
runtest/cve +1 -0
@@ -32,3 +32,4 @@ cve-2017-5754 meltdown cve-2017-17052 cve-2017-17052 cve-2017-16939 cve-2017-16939 cve-2017-17053 cve-2017-17053 +cve-2017-18075 cve-2017-18075
testcases/cve/.gitignore +1 -0
@@ -14,3 +14,4 @@ stack_clash cve-2017-17052 cve-2017-16939 cve-2017-17053 +cve-2017-18075
testcases/cve/cve-2017-18075.c new file +201 -0
201 lines not on this page · raw message
Signature · 1 line
2.16.2
PATCH 2/2 Add CVE-2017-18075, pcrypt mishandles freeing instances
Quoted 5 lines · Richard Palethorpe
Signed-off-by Richard Palethorpe <[email protected]>---
I can not find the original reproducer posted upstream. I assume it was created by syzkaller.
Yes: https://groups.google.com/forum/#!topic/syzkaller-bugs/NKn_ivoPOpk
However, this rewrite to crypto's netlink interface might be different enough such that ...
testcases/cve/cve-2017-18075.c line 7
Quoted 13 lines
testcases/cve/cve-2017-18075.c new file +7
-0@@ -0,0 +1,201 @@ +/* +* Copyright (c) 2018 SUSE +* Author: Nicolai Stange <[email protected]> +* LTP conversion: Richard Palethorpe <[email protected]> +* +* Based on the reproducer posted upstream so other copyrights may +* apply.
... this isn't really needed, but I'm not a lawyer.
Thanks,
Nicolai
Quoted 21 lines
testcases/cve/cve-2017-18075.c new file +21
-0+* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>. +* +* Test for CVE-2017-5754 - pcrypt mishandles freeing instances +* +* See commit d76c68109f37 crypto: pcrypt - fix freeing pcrypt instances. +* +* If the bug is present this will most likely crash your kernel. +*/ +
Signature · 2 lines
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
PATCH 2/2 Add CVE-2017-18075, pcrypt mishandles freeing instances
Hello,
Quoted 30 lines · Nicolai Stange
Quoted 5 lines · Richard Palethorpe
Signed-off-by Richard Palethorpe <[email protected]>---
I can not find the original reproducer posted upstream. I assume it was created by syzkaller.
Yes: https://groups.google.com/forum/#!topic/syzkaller-bugs/NKn_ivoPOpk
However, this rewrite to crypto's netlink interface might be different enough such that ...
testcases/cve/cve-2017-18075.c line 7
Quoted 13 lines
testcases/cve/cve-2017-18075.c new file +7
-0@@ -0,0 +1,201 @@ +/* +* Copyright (c) 2018 SUSE +* Author: Nicolai Stange <[email protected]> +* LTP conversion: Richard Palethorpe <[email protected]> +* +* Based on the reproducer posted upstream so other copyrights may +* apply. ... this isn't really needed, but I'm not a lawyer.
Quoted 4 lines
Thanks,
Nicolai
I will just replace it with a link to the Syzkaller reproducer (mainly just for people's information). Thanks.
Quoted 15 lines
Quoted 15 lines
testcases/cve/cve-2017-18075.c new file +13
-0+* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version 2 +* of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, see <http://www.gnu.org/licenses/>.
Quoted 8 lines
testcases/cve/cve-2017-18075.c line 28
Quoted 8 lines
testcases/cve/cve-2017-18075.c new file +8
-0+* +* Test for CVE-2017-5754 - pcrypt mishandles freeing instances +* +* See commit d76c68109f37 crypto: pcrypt - fix freeing pcrypt instances. +* +* If the bug is present this will most likely crash your kernel. +*/ +
--
Thank you,
Richard.
PATCH 2/2 Add CVE-2017-18075, pcrypt mishandles freeing instances
In reply to Richard PalethorpeHi Richard,
Quoted 6 lines · Richard Palethorpe
Signed-off-by Richard Palethorpe <[email protected]>---
I can not find the original reproducer posted upstream. I assume it was created by syzkaller.
Quoted 6 lines
This patch will not display error messages correctly without the previous TRERRNO patch I posted.
runtest/cve | 1 + testcases/cve/.gitignore | 1 + testcases/cve/cve-2017-18075.c | 201 +++++++++++++++++++++++++++++++++++++++++
Thanks for writing an LTP test for this!
Just my 2 cents, but I think it is insane to be naming tests after CVE numbers instead of putting them in an appropriate place, like a crypto/ directory for this one. People aren't going to remember what "CVE-2017-18075" is. I'm even the person who fixed this bug and requested this CVE, and I still didn't recognize the CVE number; this patch only drew my attention because the subject line mentioned pcrypt. (And now I see that I missed the recent test for the modify_ldt() use-after-free bug because the patch subject line and description only mentioned "CVE-2017-17053".)
Note that you can still put the test in the "cve" runtest file even if the test is not in the cve/ directory.
(More comments below)
Quoted 1 line
testcases/cve/cve-2017-18075.c +0
-0
[...]
Quoted 116 lines
testcases/cve/cve-2017-18075.c +116
-0+ +#define ATTEMPTS 10000 + +enum { +CRYPTO_MSG_BASE =0x10 , +CRYPTO_MSG_NEWALG =0x10 , +CRYPTO_MSG_DELALG , +CRYPTO_MSG_UPDATEALG , +CRYPTO_MSG_GETALG , +CRYPTO_MSG_DELRNG , + __CRYPTO_MSG_MAX +}; + +#define CRYPTO_MAX_ALG_NAME 64 +#define CRYPTO_MAX_NAME CRYPTO_MAX_ALG_NAME + +#define CRYPTO_ALG_TYPE_MASK 0x0000000f +#define CRYPTO_ALG_TYPE_AEAD 0x00000003 + +#ifndef NETLINK_CRYPTO +#define NETLINK_CRYPTO 21 +#endif + +struct crypto_user_alg { +char cru_name[CRYPTO_MAX_ALG_NAME ]; +char cru_driver_name[CRYPTO_MAX_ALG_NAME ]; +char cru_module_name[CRYPTO_MAX_ALG_NAME ]; +uint32_t cru_type; +uint32_t cru_mask; +uint32_t cru_refcnt; +uint32_t cru_flags; +}; + +static void send_nl_msg (int fd,struct nlmsghdr *nh,void *payload) +{ +static unsigned int sequence_number; +struct sockaddr_nl sa = { .nl_family =AF_NETLINK }; +struct iovec iov[2 ] = { + {nh,sizeof (*nh)}, + {payload, nh->nlmsg_len -sizeof (*nh)} + }; +struct msghdr msg = { + .msg_name = &sa, + .msg_namelen =sizeof (sa), + .msg_iov = iov, + .msg_iovlen =2 + }; + + nh->nlmsg_pid =0 ; + nh->nlmsg_seq = ++sequence_number; +/* Request an ack from kernel by setting NLM_F_ACK */ + nh->nlmsg_flags |=NLM_F_ACK ; + +SAFE_SENDMSG (nh->nlmsg_len, fd, &msg,0 ); +} + +static int read_reply (int fd) +{ +int len; +char buf[4096 ]; +struct iovec iov = { buf,sizeof (buf) }; +struct sockaddr_nl sa; +struct msghdr msg = { + .msg_name = &sa, + .msg_namelen =sizeof (sa), + .msg_iov = &iov, + .msg_iovlen =1 + }; +struct nlmsghdr *nh; + + len =SAFE_RECVMSG (0 , fd, &msg,0 ); + +for (nh = (struct nlmsghdr *) buf; +NLMSG_OK (nh, len); + nh =NLMSG_NEXT (nh, len)) { +/* The end of multipart message. */ +if (nh->nlmsg_type ==NLMSG_DONE ) +return 0 ; + +if (nh->nlmsg_type ==NLMSG_ERROR ) +return ((struct nlmsgerr *)NLMSG_DATA (nh))->error; + } + +return 0 ; +} + +static int add_alg (int fd,struct crypto_user_alg *a) +{ +int r; +struct nlmsghdr nh = { + .nlmsg_len =sizeof (struct nlmsghdr ) +sizeof (*a), + .nlmsg_type =CRYPTO_MSG_NEWALG , + .nlmsg_flags =NLM_F_REQUEST , + }; + +send_nl_msg (fd, &nh, a); + + r =read_reply (fd); +if (r == -EEXIST ) +return 0 ; +return r; +} + +static int del_alg (int fd,struct crypto_user_alg *a) +{ +int i; +struct timespec delay = { .tv_nsec =1000000 }; +struct nlmsghdr nh = { + .nlmsg_len =sizeof (struct nlmsghdr ) +sizeof (*a), + .nlmsg_type =CRYPTO_MSG_DELALG , + .nlmsg_flags =NLM_F_REQUEST , + }; + +for (i =0 ; i <1000 ; i++) { +send_nl_msg (fd, &nh, a); +
testcases/cve/cve-2017-18075.c line 162
Quoted 10 lines
testcases/cve/cve-2017-18075.c +10
-0+TEST (read_reply (fd)); +if (TEST_RETURN != -EBUSY ) +break ; + +if (nanosleep (&delay,NULL ) && errno !=EINTR ) +tst_brk (TBROK |TERRNO ,"nanosleep" ); + } + +return TEST_RETURN ; +}
I suggest putting this NETLINK_CRYPTO stuff in a common location that can be used by other tests too. This will not be the last crypto API bug. The definitions for AF_ALG probably should be there too; though AF_ALG isn't used by this test, many crypto bugs I've fixed or seen fixed recently are accessible through it. (E.g. see commit ecaaab564978, "crypto: salsa20 - fix blkcipher_walk API usage" or commit e57121d08c38, "crypto: chacha20poly1305 - validate the digest size". Sorry, I was a bit lazy by just putting reproducers in the commit messages and not writing "real" tests.) It would be great to have helper functions in LTP for testing the crypto API, so that they don't have to be repeated in every test.
Quoted 6 lines
testcases/cve/cve-2017-18075.c +6
-0+ +void setup (void ) +{ +tst_taint_init (TST_TAINT_W |TST_TAINT_D ); +} +
testcases/cve/cve-2017-18075.c line 178
Quoted 10 lines
testcases/cve/cve-2017-18075.c +10
-0+void run (void ) +{ +int fd, i; +struct crypto_user_alg a = { + .cru_driver_name ="pcrypt(authenc(hmac(sha256-generic),cbc(aes-generic)))" , + .cru_type =CRYPTO_ALG_TYPE_AEAD , + .cru_mask =CRYPTO_ALG_TYPE_MASK , + }; + + fd =SAFE_SOCKET (AF_NETLINK ,SOCK_DGRAM ,NETLINK_CRYPTO );
Does this test get correctly skipped if the needed crypto modules are not enabled? There are several cases:
- NETLINK_CRYPTO unsupported (CONFIG_CRYPTO_USER not set)
- pcrypt unsupported (CONFIG_CRYPTO_PCRYPT not set)
- underlying algorithms unsupported (CONFIG_CRYPTO_AUTHENC, CONFIG_CRYPTO_HMAC, CONFIG_CRYPTO_SHA256, CONFIG_CRYPTO_CBC, or CONFIG_CRYPTO_AES not set)
testcases/cve/cve-2017-18075.c line 201
Quoted 6 lines
testcases/cve/cve-2017-18075.c +6
-0+static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .min_kver ="4.2.0" , +};
Why is a minimum kernel version needed?
- Eric
PATCH 2/2 Add CVE-2017-18075, pcrypt mishandles freeing instances
Hello Eric,
Quoted 27 lines · Eric Biggers
Hi Richard,
Quoted 6 lines · Richard Palethorpe
Signed-off-by Richard Palethorpe <[email protected]>---
I can not find the original reproducer posted upstream. I assume it was created by syzkaller.
Quoted 6 lines
This patch will not display error messages correctly without the previous TRERRNO patch I posted.
runtest/cve | 1 + testcases/cve/.gitignore | 1 + testcases/cve/cve-2017-18075.c | 201 +++++++++++++++++++++++++++++++++++++++++Thanks for writing an LTP test for this!
Just my 2 cents, but I think it is insane to be naming tests after CVE numbers instead of putting them in an appropriate place, like a
crypto/directory for this one. People aren't going to remember what "CVE-2017-18075" is. I'm even the person who fixed this bug and requested this CVE, and I still didn't recognize the CVE number; this patch only drew my attention because the subject line mentioned pcrypt. (And now I see that I missed the recent test for themodify_ldt()use-after-free bug because the patch subject line and description only mentioned "CVE-2017-17053".)
Quoted 2 lines
Note that you can still put the test in the "cve" runtest file even if the test is not in the cve/ directory.
I'm happy to put it in kernel/crypto. I just wasn't sure where to put it so submitted it under the CVE directory. I guess I should have CC'ed you.
Quoted 134 lines
(More comments below)
Quoted 1 line
testcases/cve/cve-2017-18075.c +0
-0[...]
Quoted 116 lines
testcases/cve/cve-2017-18075.c +116
-0+ +#define ATTEMPTS 10000 + +enum { +CRYPTO_MSG_BASE =0x10 , +CRYPTO_MSG_NEWALG =0x10 , +CRYPTO_MSG_DELALG , +CRYPTO_MSG_UPDATEALG , +CRYPTO_MSG_GETALG , +CRYPTO_MSG_DELRNG , + __CRYPTO_MSG_MAX +}; + +#define CRYPTO_MAX_ALG_NAME 64 +#define CRYPTO_MAX_NAME CRYPTO_MAX_ALG_NAME + +#define CRYPTO_ALG_TYPE_MASK 0x0000000f +#define CRYPTO_ALG_TYPE_AEAD 0x00000003 + +#ifndef NETLINK_CRYPTO +#define NETLINK_CRYPTO 21 +#endif + +struct crypto_user_alg { +char cru_name[CRYPTO_MAX_ALG_NAME ]; +char cru_driver_name[CRYPTO_MAX_ALG_NAME ]; +char cru_module_name[CRYPTO_MAX_ALG_NAME ]; +uint32_t cru_type; +uint32_t cru_mask; +uint32_t cru_refcnt; +uint32_t cru_flags; +}; + +static void send_nl_msg (int fd,struct nlmsghdr *nh,void *payload) +{ +static unsigned int sequence_number; +struct sockaddr_nl sa = { .nl_family =AF_NETLINK }; +struct iovec iov[2 ] = { + {nh,sizeof (*nh)}, + {payload, nh->nlmsg_len -sizeof (*nh)} + }; +struct msghdr msg = { + .msg_name = &sa, + .msg_namelen =sizeof (sa), + .msg_iov = iov, + .msg_iovlen =2 + }; + + nh->nlmsg_pid =0 ; + nh->nlmsg_seq = ++sequence_number; +/* Request an ack from kernel by setting NLM_F_ACK */ + nh->nlmsg_flags |=NLM_F_ACK ; + +SAFE_SENDMSG (nh->nlmsg_len, fd, &msg,0 ); +} + +static int read_reply (int fd) +{ +int len; +char buf[4096 ]; +struct iovec iov = { buf,sizeof (buf) }; +struct sockaddr_nl sa; +struct msghdr msg = { + .msg_name = &sa, + .msg_namelen =sizeof (sa), + .msg_iov = &iov, + .msg_iovlen =1 + }; +struct nlmsghdr *nh; + + len =SAFE_RECVMSG (0 , fd, &msg,0 ); + +for (nh = (struct nlmsghdr *) buf; +NLMSG_OK (nh, len); + nh =NLMSG_NEXT (nh, len)) { +/* The end of multipart message. */ +if (nh->nlmsg_type ==NLMSG_DONE ) +return 0 ; + +if (nh->nlmsg_type ==NLMSG_ERROR ) +return ((struct nlmsgerr *)NLMSG_DATA (nh))->error; + } + +return 0 ; +} + +static int add_alg (int fd,struct crypto_user_alg *a) +{ +int r; +struct nlmsghdr nh = { + .nlmsg_len =sizeof (struct nlmsghdr ) +sizeof (*a), + .nlmsg_type =CRYPTO_MSG_NEWALG , + .nlmsg_flags =NLM_F_REQUEST , + }; + +send_nl_msg (fd, &nh, a); + + r =read_reply (fd); +if (r == -EEXIST ) +return 0 ; +return r; +} + +static int del_alg (int fd,struct crypto_user_alg *a) +{ +int i; +struct timespec delay = { .tv_nsec =1000000 }; +struct nlmsghdr nh = { + .nlmsg_len =sizeof (struct nlmsghdr ) +sizeof (*a), + .nlmsg_type =CRYPTO_MSG_DELALG , + .nlmsg_flags =NLM_F_REQUEST , + }; + +for (i =0 ; i <1000 ; i++) { +send_nl_msg (fd, &nh, a); +testcases/cve/cve-2017-18075.c line 162
Quoted 10 lines
testcases/cve/cve-2017-18075.c +10
-0+TEST (read_reply (fd)); +if (TEST_RETURN != -EBUSY ) +break ; + +if (nanosleep (&delay,NULL ) && errno !=EINTR ) +tst_brk (TBROK |TERRNO ,"nanosleep" ); + } + +return TEST_RETURN ; +}I suggest putting this
NETLINK_CRYPTOstuff in a common location that can be used by other tests too. This will not be the last crypto API bug. The
Quoted 8 lines
definitions for
AF_ALGprobably should be there too; thoughAF_ALGisn't used by this test, many crypto bugs I've fixed or seen fixed recently are accessible through it. (E.g. see commitecaaab564978, "crypto: salsa20 - fixblkcipher_walkAPI usage" or commite57121d08c38, "crypto: chacha20poly1305 - validate the digest size". Sorry, I was a bit lazy by just putting reproducers in the commit messages and not writing "real" tests.) It would be great to have helper functions in LTP for testing the crypto API, so that they don't have to be repeated in every test.
I suppose we would benefit from some generic netlink helper functions also. In my netlink.h there are about 21 different protocols defined, so we could create include/tst_netlink.h and then add include/tst_netlink_crypto.h and tst_netlink_route.h etc.
Currently we only have a few tests using netlink and they are mostly doing their own thing.
Quoted 35 lines
Quoted 7 lines
testcases/cve/cve-2017-18075.c +6
-0+ +void setup (void ) +{ +tst_taint_init (TST_TAINT_W |TST_TAINT_D ); +} +testcases/cve/cve-2017-18075.c line 178
Quoted 10 lines
testcases/cve/cve-2017-18075.c +10
-0+void run (void ) +{ +int fd, i; +struct crypto_user_alg a = { + .cru_driver_name ="pcrypt(authenc(hmac(sha256-generic),cbc(aes-generic)))" , + .cru_type =CRYPTO_ALG_TYPE_AEAD , + .cru_mask =CRYPTO_ALG_TYPE_MASK , + }; + + fd =SAFE_SOCKET (AF_NETLINK ,SOCK_DGRAM ,NETLINK_CRYPTO );Does this test get correctly skipped if the needed crypto modules are not enabled? There are several cases:
-
NETLINK_CRYPTOunsupported (CONFIG_CRYPTO_USERnot set)
- pcrypt unsupported (CONFIG_CRYPTO_PCRYPTnot set)
- underlying algorithms unsupported (CONFIG_CRYPTO_AUTHENC,CONFIG_CRYPTO_HMAC,CONFIG_CRYPTO_SHA256,CONFIG_CRYPTO_CBC, orCONFIG_CRYPTO_AESnot set)testcases/cve/cve-2017-18075.c line 201
Quoted 6 lines
testcases/cve/cve-2017-18075.c +6
-0+static struct tst_test test = { + .setup = setup, + .test_all = run, + .needs_root =1 , + .min_kver ="4.2.0" , +};Why is a minimum kernel version needed?
Quoted 1 line
- Eric
So this is wrong then, I need to check the errno of socket() when it fails and can remove the min_kver which I think was the kernel version where the feature was introduced.
--
Thank you,
Richard.
PATCH 2/2 Add CVE-2017-18075, pcrypt mishandles freeing instances
In reply to Eric BiggersHi!
Quoted 6 lines
Quoted 3 lines
runtest/cve | 1 + testcases/cve/.gitignore | 1 + testcases/cve/cve-2017-18075.c | 201 +++++++++++++++++++++++++++++++++++++++++Thanks for writing an LTP test for this!
Quoted 8 lines
Just my 2 cents, but I think it is insane to be naming tests after CVE numbers instead of putting them in an appropriate place, like a
crypto/directory for this one. People aren't going to remember what "CVE-2017-18075" is. I'm even the person who fixed this bug and requested this CVE, and I still didn't recognize the CVE number; this patch only drew my attention because the subject line mentioned pcrypt. (And now I see that I missed the recent test for themodify_ldt()use-after-free bug because the patch subject line and description only mentioned "CVE-2017-17053".)
Agreed, the numbers suck, I have to read everything twice to avoid typos.
Maybe we should name the test files after the kernel subsystem with an increasing counter as a last resort.
Quoted 10 lines
I suggest putting this
NETLINK_CRYPTOstuff in a common location that can be used by other tests too. This will not be the last crypto API bug. The definitions forAF_ALGprobably should be there too; thoughAF_ALGisn't used by this test, many crypto bugs I've fixed or seen fixed recently are accessible through it. (E.g. see commitecaaab564978, "crypto: salsa20 - fixblkcipher_walkAPI usage" or commite57121d08c38, "crypto: chacha20poly1305 - validate the digest size". Sorry, I was a bit lazy by just putting reproducers in the commit messages and not writing "real" tests.) It would be great to have helper functions in LTP for testing the crypto API, so that they don't have to be repeated in every test.
We do have include/lapi/ headers for that purpose, we may as well put it there.
Signature · 2 lines
Cyril Hrubis [email protected]
PATCH 1/2 lib: Add safe_recvmsg
In reply to Richard PalethorpeHi,
Quoted 61 lines
Identical to
safe_sendmsgexcept *msg is not const.Signed-off-by Richard Palethorpe <[email protected]>--- include/safe_net_fn.h | 3 +++ include/tst_safe_net.h | 3 +++ lib/safe_net.c | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+)include/safe_net_fn.h +3
-0@@ -49,6 +49,9 @@ ssize_t safe_sendto(const char *file, const int lineno, char len_strict,ssize_t safe_sendmsg (const char *file,const int lineno,size_t msg_len,int sockfd,const struct msghdr *msg,int flags); +ssize_t safe_recvmsg (const char *file,const int lineno,size_t msg_len, +int sockfd,struct msghdr *msg,int flags); +int safe_bind (const char *file,const int lineno,void (cleanup_fn )(void ),int socket,const struct sockaddr *address,socklen_t address_len);include/tst_safe_net.h +3
-0@@ -54,6 +54,9 @@#define SAFE_SENDMSG (msg_len, fd, msg, flags) \ safe_sendmsg(__FILE__, __LINE__, msg_len, fd, msg, flags) +#define SAFE_RECVMSG (msg_len, fd, msg, flags) \ + safe_recvmsg(__FILE__, __LINE__, msg_len, fd, msg, flags) +#define SAFE_BIND (socket, address, address_len) \ safe_bind(__FILE__, __LINE__, NULL, socket, address, \ address_len)lib/safe_net.c +16
-0@@ -209,6 +209,29 @@ ssize_t safe_sendmsg(const char *file, const int lineno, size_t len,return rval; } +ssize_t safe_recvmsg (const char *file,const int lineno,size_t len, +int sockfd,struct msghdr *msg,int flags) +{ +ssize_t rval; + + rval =recvmsg (sockfd, msg, flags); + +if (rval ==-1 ) { +tst_brkm (TBROK |TERRNO ,NULL , +"%s:%d: recvmsg(%d, %p, %d) failed" , + file, lineno, sockfd, msg, flags); + } + +if (len && (size_t )rval != len) { + tst_brkm(TBROK, NULL, + "%s:%d: recvmsg(%d, %p, %d) ret(%zd) != len(%zu)",
lib/safe_net.c ssize_t safe_sendmsg(const char *file, const int lineno, size_t len, · line 237
Quoted 10 lines
lib/safe_net.c +7
-0+ file, lineno, sockfd, msg, flags, rval, len); + } + +return rval; + +} +int safe_bind (const char *file,const int lineno,void (cleanup_fn )(void ),int socket,const struct sockaddr *address,socklen_t address_len)
Obviously correct :).
Kind regards,
Petr
PATCH 1/2 lib: Add safe_recvmsg
Hi,
Quoted 73 lines
Quoted 61 lines
Identical to
safe_sendmsgexcept *msg is not const.Signed-off-by Richard Palethorpe <[email protected]>--- include/safe_net_fn.h | 3 +++ include/tst_safe_net.h | 3 +++ lib/safe_net.c | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+)include/safe_net_fn.h +3
-0@@ -49,6 +49,9 @@ ssize_t safe_sendto(const char *file, const int lineno, char len_strict,ssize_t safe_sendmsg (const char *file,const int lineno,size_t msg_len,int sockfd,const struct msghdr *msg,int flags); +ssize_t safe_recvmsg (const char *file,const int lineno,size_t msg_len, +int sockfd,struct msghdr *msg,int flags); +int safe_bind (const char *file,const int lineno,void (cleanup_fn )(void ),int socket,const struct sockaddr *address,socklen_t address_len);include/tst_safe_net.h +3
-0@@ -54,6 +54,9 @@#define SAFE_SENDMSG (msg_len, fd, msg, flags) \ safe_sendmsg(__FILE__, __LINE__, msg_len, fd, msg, flags) +#define SAFE_RECVMSG (msg_len, fd, msg, flags) \ + safe_recvmsg(__FILE__, __LINE__, msg_len, fd, msg, flags) +#define SAFE_BIND (socket, address, address_len) \ safe_bind(__FILE__, __LINE__, NULL, socket, address, \ address_len)lib/safe_net.c +16
-0@@ -209,6 +209,29 @@ ssize_t safe_sendmsg(const char *file, const int lineno, size_t len,return rval; } +ssize_t safe_recvmsg (const char *file,const int lineno,size_t len, +int sockfd,struct msghdr *msg,int flags) +{ +ssize_t rval; + + rval =recvmsg (sockfd, msg, flags); + +if (rval ==-1 ) { +tst_brkm (TBROK |TERRNO ,NULL , +"%s:%d: recvmsg(%d, %p, %d) failed" , + file, lineno, sockfd, msg, flags); + } + +if (len && (size_t )rval != len) { + tst_brkm(TBROK, NULL, + "%s:%d: recvmsg(%d, %p, %d) ret(%zd) != len(%zu)",lib/safe_net.c ssize_t safe_sendmsg(const char *file, const int lineno, size_t len, · line 237
Quoted 10 lines
lib/safe_net.c +7
-0+ file, lineno, sockfd, msg, flags, rval, len); + } + +return rval; + +} +int safe_bind (const char *file,const int lineno,void (cleanup_fn )(void ),int socket,const struct sockaddr *address,socklen_t address_len)Obviously correct :).
Quoted 1 line
Acked-by Petr Vorel <[email protected]>
Pushed, thanks!
Kind regards,
Petr