From patchwork Mon Oct 24 11:29:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 8567 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp418005wru; Mon, 24 Oct 2022 05:13:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6T/jGjMaya64c1dEh5Lsov4rgtUCHFNUXAWdc4DuUwcM9vCxrs0Ve83OujblOYYVRJ6g1T X-Received: by 2002:aa7:cc13:0:b0:453:52dc:1bbf with SMTP id q19-20020aa7cc13000000b0045352dc1bbfmr30851423edt.30.1666613638619; Mon, 24 Oct 2022 05:13:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666613638; cv=none; d=google.com; s=arc-20160816; b=zsBqduaS29FhkBpOCebV0IZs0Rmw2PeDxeFrYfjXxaz6+KdTh2WOSKoypM64ZmKxLX wMj9GYD/emD3EyqEJtBMTRbsa8sX9XRJMWda8F74rDw9HyYP+5+dLCQElhpaSEJSRIQ7 iQ52Zpkeu82vuFl7xAABefcMkVc8+K8x2JO9ED61nmJP15YVVHYJThQrcQGxBCi4Kdin p6TidZ+V3Vq5tQBk3l+s81+VQGgvr72fFUVy7Q4lSKlon0C2+wa708TD52o77M3NjIKb 81vWa4v2pW+BAQHqVuwbG7U0S3fi9wvpQA+Tprh91ah7gW7mYh7ui7pIezkD+OBdNgXZ thng== 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=F8ox9Wu+RF/nLBnyZrSC09S6EScztHAHmH0KKFvMPuY=; b=d1wtywqYayySa3yCRwzz0k4+IaANGMTaZ9lLfNpZs6c6iG4pkrLtFezLRMOQES9zCh vikAWtcjhQ1odTFh+Z1XQ9Oy3vCpfIZyYneM/FHfIVlBtRmA6UNcK4gSJez3Yvfq7DfV oct7amLqRBvTamY60u8Y55gct6jVhcPgWNa0mFKXDO4mOIADJQHW4AjBvCArA2zs/2rx ZY7SotlxRROtro8yji98+5zEe6u8KtGvQ5c9eXDoJr5LbfqpEebCS57qTzWXLlgxNyhd aKiRX3UBL0eI12EiwHr+0CQVAdNz0rOa0/nuZScLZ7M3nwOyWlF17F+DjuYKFjvxk8Z4 q4uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=MVGIaP64; 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 sg10-20020a170907a40a00b0079b40c09982si9204664ejc.340.2022.10.24.05.13.32; Mon, 24 Oct 2022 05:13:58 -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=MVGIaP64; 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 S232263AbiJXMFR (ORCPT + 99 others); Mon, 24 Oct 2022 08:05:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232286AbiJXMCU (ORCPT ); Mon, 24 Oct 2022 08:02:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1EEE32495B; Mon, 24 Oct 2022 04:49:47 -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 4D4A6612C9; Mon, 24 Oct 2022 11:46:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CACCC433D7; Mon, 24 Oct 2022 11:46:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611998; bh=qRqcUUTGz48ylilhA9AgVfT7w9HHuLUTCmZjZVP6zcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MVGIaP64f15RCwlyI38wVCDZ8zr0316twfNnAnQ3wk066eDjUsWpU9yp5BiMT2bHX hlUYPnvleVQc04w6sl+BlISAllTUXOt54BCJQAG4r+Fu7P4sFvV5TJMLuzQ4b/dxo9 oWMs46EhtthhvzfR+cebjdr0vbIpTAzcKGFjXphs= 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.14 030/210] usb: mon: make mmapped memory read only Date: Mon, 24 Oct 2022 13:29:07 +0200 Message-Id: <20221024112957.939635963@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112956.797777597@linuxfoundation.org> References: <20221024112956.797777597@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?1747571062338547519?= X-GMAIL-MSGID: =?utf-8?q?1747571062338547519?= 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 @@ -1267,6 +1267,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);