From patchwork Mon Oct 24 11:28:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8677 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp422203wru; Mon, 24 Oct 2022 05:22:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6mitnBBDFeTYuGhIVV9aQ3hDd4WQQZa2XHH/092n1M1YzuQBSAPsbqVd9daoRovd7Q/ohi X-Received: by 2002:a17:906:846c:b0:7a5:ccb:c174 with SMTP id hx12-20020a170906846c00b007a50ccbc174mr6228430ejc.583.1666614126194; Mon, 24 Oct 2022 05:22:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666614126; cv=none; d=google.com; s=arc-20160816; b=GPTC/FOYhPlAq/iP1YPugOrajCSs8h0CGKZw0a6OpnBNCwOVKomcc3/i2EpM5CD6EP Xbhu7kDAVqf9qdnr9zimzkiY617MRB9SkJHnip+PHMenC15c+B6etgFGqCc/OP+mRrJA 7tRahAehQ/sU+FLBgQDKVDXeEeJxHNgBGwIDrkVYkoLTlV6ro9K++0YPvWOYOmLId40f 0wJcqD0szrATY5v+SZcO05WceX7WcZ+QIppCa9D916k0cJfXQtZfzVDZ5pKOyCgFGL2q 2Ey34TXdKKsA5oM78Eou3fLt4t0nKdECXfM/cx5kYbkT3r07BoajmdIaGz2RSQSxEXJK TWZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=/99HhorlSEtRK1O8lF2dwiBzQkiIMdwAYwHSdrKnUc4=; b=w1xMgPqg6kel0Mnv8Fx2oTtjeQn6DfkNaiWq2HUcPtQByx332XJ8PFKavEDRkOzkOv SoZRdS0aGxtajL5zxxKH7iCsZKRJxu0IfbB0UAKKl5gs8qoIgHomCSX46IZ6DD1pd15e +ZqKsyOq+A60ZqXWOUFNPjmaNUuXd93DN3hocMvi84g32LD6mueOJ8410LNfRikkpXwt 59px0M8wg5e1dNPkGykGg4Y5HgiG3N1KiYPCftyhZBdIcuKq86L+BgoQ7iMPNiw3jOMj O3mQkt5oF5RO8p5vEljZ1Ckddr6H1UFUdsYZRFaXcJ0juw3+ZbMhhdMtSgGdlpcWcBjt 2AqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MNeRCenC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sz15-20020a1709078b0f00b007313312730esi21657643ejc.85.2022.10.24.05.21.42; Mon, 24 Oct 2022 05:22:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MNeRCenC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232587AbiJXMUA (ORCPT + 99 others); Mon, 24 Oct 2022 08:20:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233005AbiJXMSn (ORCPT ); Mon, 24 Oct 2022 08:18:43 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E365080E95; Mon, 24 Oct 2022 04:57:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A4DE061291; Mon, 24 Oct 2022 11:55:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4955C433C1; Mon, 24 Oct 2022 11:55:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666612505; bh=xxDHkhWXn9LWoUKnTOuFYR63Zphxmul0hUMh47XisPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MNeRCenC61q5K5K3kG+Mt7NSuMhycgfio2NCGHyKPMBWhHoZQ9qnuKRq66fgXLgTE KAK+LZ3H986RgVy0dUa3UI4sZO0Ql8iY7bE03ITswmitogBDsIjaRhGAUJLBAg9xu5 QJJMbS+eMxzTEEO+1h9/DZoF2YKp+BJHwOlEtlf4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Dmitry Vyukov" , stable , syzbot+23f57c5ae902429285d7@syzkaller.appspotmail.com, Tadeusz Struk , PaX Team Subject: [PATCH 4.19 013/229] usb: mon: make mmapped memory read only Date: Mon, 24 Oct 2022 13:28:52 +0200 Message-Id: <20221024112959.566961406@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112959.085534368@linuxfoundation.org> References: <20221024112959.085534368@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747571573965668077?= X-GMAIL-MSGID: =?utf-8?q?1747571573965668077?= From: Tadeusz Struk commit a659daf63d16aa883be42f3f34ff84235c302198 upstream. 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" Cc: stable Fixes: 6f23ee1fefdc ("USB: add binary API to usbmon") Suggested-by: PaX Team # for the VM_MAYRITE portion Link: https://syzkaller.appspot.com/bug?id=2eb1f35d6525fa4a74d75b4244971e5b1411c95a Reported-by: syzbot+23f57c5ae902429285d7@syzkaller.appspotmail.com Signed-off-by: Tadeusz Struk Link: https://lore.kernel.org/r/20220919215957.205681-1-tadeusz.struk@linaro.org Signed-off-by: Greg Kroah-Hartman --- drivers/usb/mon/mon_bin.c | 5 +++++ 1 file changed, 5 insertions(+) --- 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 *fil { /* 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);