From: Petr Vorel <pvorel@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 4/4] Add test for CVE 2020-29373
Date: Fri, 5 Feb 2021 17:49:32 +0100 [thread overview]
Message-ID: <YB13HM7so0YBwO8v@pevik> (raw)
In-Reply-To: <20210204110342.11821-4-mdoucha@suse.cz>
Hi Martin,
> Fixes #770
Nice port thanks!
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Few questions below.
...
> +static void run(void)
> +{
> + uint32_t i, count, tail;
> + int beef_found = 0;
> + struct io_uring_sqe *sqe_ptr;
> + const struct io_uring_cqe *cqe_ptr;
> +
> + SAFE_SOCKETPAIR(AF_UNIX, SOCK_DGRAM, 0, sockpair);
> + SAFE_SETSOCKOPT_INT(sockpair[0], SOL_SOCKET, SO_SNDBUF,
> + 32+sizeof(buf));
> + SAFE_FCNTL(sockpair[0], F_SETFL, O_NONBLOCK);
> +
> + SAFE_IO_URING_INIT(512, ¶ms, &uring);
> + sqe_ptr = uring.sqr_entries;
> +
> + /* Add spam requests to force async processing of the real test */
> + for (i = 0, tail = *uring.sqr_tail; i < 255; i++, tail++, sqe_ptr++) {
> + memset(sqe_ptr, 0, sizeof(*sqe_ptr));
> + sqe_ptr->opcode = IORING_OP_SENDMSG;
> + sqe_ptr->flags = IOSQE_IO_DRAIN;
> + sqe_ptr->fd = sockpair[0];
> + sqe_ptr->addr = (__u64)&spam_header;
> + sqe_ptr->user_data = SPAM_MARK;
Interesting, original reproducer uses here i
> + uring.sqr_array[tail & *uring.sqr_mask] = i;
> + }
> +
> + /* Add the real test to queue */
> + memset(sqe_ptr, 0, sizeof(*sqe_ptr));
> + sqe_ptr->opcode = IORING_OP_SENDMSG;
> + sqe_ptr->flags = IOSQE_IO_DRAIN;
> + sqe_ptr->fd = sendsock;
> + sqe_ptr->addr = (__u64)&beef_header;
> + sqe_ptr->user_data = BEEF_MARK;
and here also 255, you use much higher 0xbeef.
You probably have a good reason to use here 0xfa7 (higher value). But maybe
explaining why?
> + uring.sqr_array[tail & *uring.sqr_mask] = i;
> + count = ++i;
> + tail++;
> +
> + __atomic_store(uring.sqr_tail, &tail, __ATOMIC_RELEASE);
> + SAFE_IO_URING_ENTER(1, uring.fd, count, count, IORING_ENTER_GETEVENTS,
> + NULL);
> +
> + /* Check test results */
> + __atomic_load(uring.cqr_tail, &tail, __ATOMIC_ACQUIRE);
> +
> + for (i = *uring.cqr_head; i != tail; i++, count--) {
> + cqe_ptr = uring.cqr_entries + (i & *uring.cqr_mask);
> + TST_ERR = -cqe_ptr->res;
> +
> + if (cqe_ptr->user_data == SPAM_MARK) {
> + if (cqe_ptr->res >= 0 || cqe_ptr->res == -EAGAIN)
> + continue;
> +
> + tst_res(TFAIL | TTERRNO,
> + "Spam request failed unexpectedly");
I'm sorry, I'm lost to which TEST*() call this TTERRNO refers (there are mostly
SAFE_*() macros.
> + continue;
> + }
> +
> + if (cqe_ptr->user_data != BEEF_MARK) {
> + tst_res(TFAIL, "Unexpected entry in completion queue");
> + count++;
> + continue;
> + }
> +
> + beef_found = 1;
> +
> + if (cqe_ptr->res >= 0) {
> + tst_res(TFAIL, "Write outside chroot succeeded.");
> + } else if (cqe_ptr->res != -ENOENT) {
> + tst_res(TFAIL | TTERRNO,
And here.
> + "Write outside chroot failed unexpectedly");
> + } else {
> + tst_res(TPASS,
> + "Write outside chroot failed as expected");
> + }
> + }
> +
> + __atomic_store(uring.cqr_head, &i, __ATOMIC_RELEASE);
> +
> + if (!beef_found)
> + tst_res(TFAIL, "Write outside chroot result not found");
> +
> + if (count)
> + tst_res(TFAIL, "Wrong number of entries in completion queue");
> +
> + /* iteration cleanup */
> + SAFE_IO_URING_CLOSE(&uring);
> + SAFE_CLOSE(sockpair[0]);
> + SAFE_CLOSE(sockpair[1]);
> +}
Kind regards,
Petr
next prev parent reply other threads:[~2021-02-05 16:49 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-04 11:03 [LTP] [PATCH v2 1/4] Prevent linker issues in lapi/io_uring.h Martin Doucha
2021-02-04 11:03 ` [LTP] [PATCH v2 2/4] Add safe functions for io_uring to LTP library Martin Doucha
2021-02-05 15:56 ` Petr Vorel
2021-02-05 16:03 ` Martin Doucha
2021-02-05 17:06 ` Petr Vorel
2021-02-04 11:03 ` [LTP] [PATCH v2 3/4] Add CAP_SYS_CHROOT to lapi/capability.h Martin Doucha
2021-02-04 11:03 ` [LTP] [PATCH v2 4/4] Add test for CVE 2020-29373 Martin Doucha
2021-02-05 16:49 ` Petr Vorel [this message]
2021-02-08 9:37 ` Martin Doucha
2021-02-08 9:48 ` Petr Vorel
2021-02-05 16:09 ` [LTP] [PATCH v2 1/4] Prevent linker issues in lapi/io_uring.h Petr Vorel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YB13HM7so0YBwO8v@pevik \
--to=pvorel@suse.cz \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.