From patchwork Thu Dec 23 10:21:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 12698072 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0A6EFC433EF for ; Thu, 23 Dec 2021 10:12:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 70B426B0072; Thu, 23 Dec 2021 05:12:08 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6934C6B0073; Thu, 23 Dec 2021 05:12:08 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 55C5B6B0074; Thu, 23 Dec 2021 05:12:08 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0095.hostedemail.com [216.40.44.95]) by kanga.kvack.org (Postfix) with ESMTP id 4148E6B0072 for ; Thu, 23 Dec 2021 05:12:08 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 0044A181AC9C6 for ; Thu, 23 Dec 2021 10:12:07 +0000 (UTC) X-FDA: 78948643536.22.B096EAF Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf03.hostedemail.com (Postfix) with ESMTP id 3253920020 for ; Thu, 23 Dec 2021 10:12:07 +0000 (UTC) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.55]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4JKQrg6bjFz1DKFD; Thu, 23 Dec 2021 18:08:51 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 23 Dec 2021 18:12:01 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Thu, 23 Dec 2021 18:12:01 +0800 From: Kefeng Wang To: Kees Cook , Laura Abbott , "Mark Rutland" , , Andrew Morton , , Michael Ellerman , Benjamin Herrenschmidt , "Paul Mackerras" , CC: Kefeng Wang Subject: [PATCH] Revert "mm/usercopy: Drop extra is_vmalloc_or_module() check" Date: Thu, 23 Dec 2021 18:21:26 +0800 Message-ID: <20211223102126.161848-1-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 3253920020 X-Stat-Signature: ygthzm4toqndsmmgcdf15oxs7iw74c6k Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com X-HE-Tag: 1640254327-591865 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: This reverts commit 517e1fbeb65f5eade8d14f46ac365db6c75aea9b. usercopy: Kernel memory exposure attempt detected from SLUB object not in SLUB page?! (offset 0, size 1048)! kernel BUG at mm/usercopy.c:99 ... usercopy_abort+0x64/0xa0 (unreliable) __check_heap_object+0x168/0x190 __check_object_size+0x1a0/0x200 dev_ethtool+0x2494/0x2b20 dev_ioctl+0x5d0/0x770 sock_do_ioctl+0xf0/0x1d0 sock_ioctl+0x3ec/0x5a0 __se_sys_ioctl+0xf0/0x160 system_call_exception+0xfc/0x1f0 system_call_common+0xf8/0x200 When run ethtool eth0, the BUG occurred, the code shows below, data = vzalloc(array_size(gstrings.len, ETH_GSTRING_LEN)); copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN)) The data is alloced by vmalloc(), virt_addr_valid(ptr) will return true on PowerPC64, which leads to the panic, add back the is_vmalloc_or_module() check to fix it. Fixes: 517e1fbeb65f (mm/usercopy: Drop extra is_vmalloc_or_module() check) Signed-off-by: Kefeng Wang --- mm/usercopy.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mm/usercopy.c b/mm/usercopy.c index b3de3c4eefba..cfc845403017 100644 --- a/mm/usercopy.c +++ b/mm/usercopy.c @@ -225,6 +225,17 @@ static inline void check_heap_object(const void *ptr, unsigned long n, { struct page *page; + /* + * Some architectures (PowerPC64) return true for virt_addr_valid() on + * vmalloced addresses. Work around this by checking for vmalloc + * first. + * + * We also need to check for module addresses explicitly since we + * may copy static data from modules to userspace + */ + if (is_vmalloc_or_module_addr(ptr)) + return; + if (!virt_addr_valid(ptr)) return;