Skip to content

Commit

Permalink
tomoyo: fix UAF write bug in tomoyo_write_control()
Browse files Browse the repository at this point in the history
commit 2f03fc340cac9ea1dc63cbf8c93dd2eb0f227815 upstream.

Since tomoyo_write_control() updates head->write_buf when write()
of long lines is requested, we need to fetch head->write_buf after
head->io_sem is held.  Otherwise, concurrent write() requests can
cause use-after-free-write and double-free problems.

Reported-by: Sam Sun <[email protected]>
Closes: https://lkml.kernel.org/r/CAEkJfYNDspuGxYx5kym8Lvp--D36CMDUErg4rxfWFJuPbbji8g@mail.gmail.com
Fixes: bd03a3e ("TOMOYO: Add policy namespace support.")
Cc:  <[email protected]> # Linux 3.1+
Signed-off-by: Tetsuo Handa <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
Tetsuo Handa authored and sfX-bot committed May 15, 2024
1 parent a442789 commit 81e94a9
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion security/tomoyo/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -2657,13 +2657,14 @@ ssize_t tomoyo_write_control(struct tomoyo_io_buffer *head,
{
int error = buffer_len;
size_t avail_len = buffer_len;
char *cp0 = head->write_buf;
char *cp0;
int idx;

if (!head->write)
return -EINVAL;
if (mutex_lock_interruptible(&head->io_sem))
return -EINTR;
cp0 = head->write_buf;
head->read_user_buf_avail = 0;
idx = tomoyo_read_lock();
/* Read a line and dispatch it to the policy handler. */
Expand Down

0 comments on commit 81e94a9

Please sign in to comment.