Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6819665rwi; Mon, 24 Oct 2022 06:33:01 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6cry7xvIEwSOHDqKiDEmp7051GdI/OeaBQklbLmu7yNMOeq/hWa6RGKElVh+fhheswtbbt X-Received: by 2002:a17:906:9bc2:b0:7a3:b186:ba68 with SMTP id de2-20020a1709069bc200b007a3b186ba68mr8182465ejc.622.1666618381232; Mon, 24 Oct 2022 06:33:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666618381; cv=none; d=google.com; s=arc-20160816; b=oi4eN0NJlmjt38oEcwWZBdsQyOlsLpmJixt1TNzxgMypL8vMJqSHKEUALXQ2AvoSm7 Y0La7afek2VNR31e1lMqY9G2r+JE39YOTMO2jOJctFq3CqZb+KcQ3UApoz27Nwhi3LL6 aCl4KSEuJ1qo7WxUZQTlXW1Dkt3ZcrXBA6nSZADsFnJya8KlwYLoJLz6JlJO+PUeJSF0 TIoeXfMqOgBoqc4GaqLYowpvBB5daMeS2NGukicnNZBHvjwBLLv3CIHowOv/i56m0ttO McEbg0ztPpHmjuqj1GowabCa8b1sfoC5gpg8kvq54TRlzNLaJGOyWrRVnsJ+0xKBd2Ko OtwA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa16-20020a170907869000b007877b1c7f27si25901516ejc.829.2022.10.24.06.32.34; Mon, 24 Oct 2022 06:33:01 -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 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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);