[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAG48ez0r4_U-9TfZOnZA0TKKPc64eYgYQt-3jHDYEqE9OuhLxQ@mail.gmail.com>
Date: Thu, 23 Jan 2025 15:44:26 +0100
From: Jann Horn <jannh@...gle.com>
To: Jens Axboe <axboe@...nel.dk>
Cc: Pavel Begunkov <asml.silence@...il.com>, io-uring@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: Re: [PATCH] io_uring/uring_cmd: add missing READ_ONCE() on shared
memory read
On Thu, Jan 23, 2025 at 1:18 AM Jens Axboe <axboe@...nel.dk> wrote:
> On 1/22/25 12:38 PM, Jens Axboe wrote:
> >
> > On Tue, 21 Jan 2025 17:09:59 +0100, Jann Horn wrote:
> >> cmd->sqe seems to point to shared memory here; so values should only be
> >> read from it with READ_ONCE(). To ensure that the compiler won't generate
> >> code that assumes the value in memory will stay constant, add a
> >> READ_ONCE().
> >> The callees io_uring_cmd_getsockopt() and io_uring_cmd_setsockopt() already
> >> do this correctly.
> >>
> >> [...]
> >
> > Applied, thanks!
> >
> > [1/1] io_uring/uring_cmd: add missing READ_ONCE() on shared memory read
> > commit: 0963dba3dc006b454c54fd019bbbdb931e7a7c70
>
> I took a closer look and this isn't necessary. Either ->sqe is a full
> copy at this point. Should probably be renamed as such... If we want to
> make this clearer, then we should do:
Are you sure? On mainline (at commit 21266b8df522), I applied the
attached diff that basically adds some printf debugging and adds this
in io_uring_cmd_sock():
pr_warn("%s: [first read] cmd->sqe->cmd_op = 0x%x\n", __func__,
READ_ONCE(cmd->sqe->cmd_op));
mdelay(2000);
pr_warn("%s: [second read] cmd->sqe->cmd_op = 0x%x\n", __func__,
READ_ONCE(cmd->sqe->cmd_op));
Then I ran the attached testcase, which submits a SQE and then
modifies the ->cmd_op of the SQE while it is being submitted.
Resulting dmesg output, showing that cmd->sqe->cmd_op changes when
userspace modifies the SQE:
[ 180.415944][ T1110] io_submit_sqes: SQE = ffff888010bcc000
[ 180.418731][ T1110] io_submit_sqe: SQE = ffff888010bcc000
[ 180.421191][ T1110] io_queue_sqe
[ 180.422160][ T1110] io_issue_sqe
[ 180.423101][ T1110] io_uring_cmd: SQE = ffff888010bcc000
[ 180.424570][ T1110] io_uring_cmd_sock: cmd->sqe = ffff888010bcc000
[ 180.426272][ T1110] io_uring_cmd_sock: [first read] cmd->sqe->cmd_op = 0x1234
[ 182.429036][ T1110] io_uring_cmd_sock: [second read]
cmd->sqe->cmd_op = 0x5678
View attachment "uring-cmd-test.c" of type "text/x-csrc" (2033 bytes)
View attachment "uring-cmd-test.diff" of type "text/x-patch" (2704 bytes)
Powered by blists - more mailing lists