All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tadeusz Struk <tadeusz.struk@linaro.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Tadeusz Struk <tadeusz.struk@linaro.org>,
	"Dmitry Vyukov" <dvyukov@google.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org, PaX Team <pageexec@freemail.hu>,
	syzbot+23f57c5ae902429285d7@syzkaller.appspotmail.com
Subject: [PATCH v2] usb: mon: make mmapped memory read only
Date: Mon, 19 Sep 2022 14:59:57 -0700	[thread overview]
Message-ID: <20220919215957.205681-1-tadeusz.struk@linaro.org> (raw)
In-Reply-To: <20220916224741.2269649-1-tadeusz.struk@linaro.org>

Syzbot found an issue in usbmon module, where the user space client
can corrupt the monitor's internal memory, causing the usbmon module
to crash the kernel with segfault, UAF, etc.
The reproducer mmaps the /dev/usbmon memory to user space, and
overwrites it with arbitrary data, which causes all kinds of issues.
Return an -EPERM error from mon_bin_mmap() if the flag VM_WRTIE is set.
Also clear VM_MAYWRITE to make it impossible to change it to writable
later.

Cc: "Dmitry Vyukov" <dvyukov@google.com>
Cc: <linux-usb@vger.kernel.org>
Cc: <linux-kernel@vger.kernel.org>
Cc: <stable@vger.kernel.org>
Fixes: 6f23ee1fefdc ("USB: add binary API to usbmon")

For the VM_MAYWRITE part:
Suggested-by: PaX Team <pageexec@freemail.hu>

Link: https://syzkaller.appspot.com/bug?id=2eb1f35d6525fa4a74d75b4244971e5b1411c95a
Reported-by: syzbot+23f57c5ae902429285d7@syzkaller.appspotmail.com
Signed-off-by: Tadeusz Struk <tadeusz.struk@linaro.org>
---
v2:
   Return an error instead of quietly clearing the flag,
   when VM_WRTIE is set. Also clear VM_MAYWRITE.
---
 drivers/usb/mon/mon_bin.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/mon/mon_bin.c b/drivers/usb/mon/mon_bin.c
index f48a23adbc35..094e812e9e69 100644
--- a/drivers/usb/mon/mon_bin.c
+++ b/drivers/usb/mon/mon_bin.c
@@ -1268,6 +1268,11 @@ static int mon_bin_mmap(struct file *filp, struct vm_area_struct *vma)
 {
 	/* don't do anything here: "fault" will set up page table entries */
 	vma->vm_ops = &mon_bin_vm_ops;
+
+	if (vma->vm_flags & VM_WRITE)
+		return -EPERM;
+
+	vma->vm_flags &= ~VM_MAYWRITE;
 	vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
 	vma->vm_private_data = filp->private_data;
 	mon_bin_vma_open(vma);
-- 
2.37.3

      parent reply	other threads:[~2022-09-19 22:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-16 22:47 [PATCH] usb: mon: make mmapped memory read only Tadeusz Struk
2022-09-17  4:14 ` Tadeusz Struk
2022-09-19  4:25 ` Dmitry Vyukov
2022-09-19 11:21   ` Dmitry Vyukov
2022-09-19 14:53   ` Tadeusz Struk
2022-09-19 21:59 ` Tadeusz Struk [this message]

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=20220919215957.205681-1-tadeusz.struk@linaro.org \
    --to=tadeusz.struk@linaro.org \
    --cc=dvyukov@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=pageexec@freemail.hu \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+23f57c5ae902429285d7@syzkaller.appspotmail.com \
    /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.