From patchwork Fri Jul 30 14:19:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 12411371 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F9DAC4320A for ; Fri, 30 Jul 2021 14:34:29 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7DFD260FE7 for ; Fri, 30 Jul 2021 14:34:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7DFD260FE7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id BD0D18D0002; Fri, 30 Jul 2021 10:34:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B59EC8D0001; Fri, 30 Jul 2021 10:34:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A21098D0002; Fri, 30 Jul 2021 10:34:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id 854548D0001 for ; Fri, 30 Jul 2021 10:34:27 -0400 (EDT) Received: from smtpin16.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 2929218416418 for ; Fri, 30 Jul 2021 14:34:27 +0000 (UTC) X-FDA: 78419499774.16.D321860 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf28.hostedemail.com (Postfix) with ESMTP id B98139001869 for ; Fri, 30 Jul 2021 14:34:26 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id C2B2860F01; Fri, 30 Jul 2021 14:34:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1627655665; bh=4DbDZVvUc+dbG0q9uR6ZqemnYmAhCvAn9+VRYxBJhvI=; h=From:To:Cc:Subject:Date:From; b=jZShBguZ6BrdR0jEvzi2jvnkksMWgh+zXosfmgZiqUARHrTF6kfh8PMj0TK2WaEuX eHQRWFgkOQIpv2JaOd+83Y8KBuhUgeYRezWyaDdS/vTcUljIFrrPBLEZYojy0RCbzy mN0DJXZQ0dnGCZsjcQpIAP6Am2CkLWc4W8Wq9AUrjHzQ4n4UdLAefDvAePtEUX0dWT SBP1k1zeZfvbY9KsdrthXqjB09OP50cSuTqvCPyAbADj6lH4DvFd/RYS+O9OtcmnmS gdQbAxdhHCDg4oZwZNI4tPZqNyoO/+nrqCv+PikfvRuQZZeKDKXMGscu7ve4CAFhSa G2E9rUn+kcyxg== From: Arnd Bergmann To: Andrew Morton , Heiko Carstens Cc: linux-mm@kvack.org, kernel@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Michal Hocko , Stephen Rothwell , Feng Tang , "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org Subject: [PATCH] fixup! mm: simplify compat numa syscalls Date: Fri, 30 Jul 2021 16:19:46 +0200 Message-Id: <20210730143417.3700653-1-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=jZShBguZ; spf=pass (imf28.hostedemail.com: domain of arnd@kernel.org designates 198.145.29.99 as permitted sender) smtp.mailfrom=arnd@kernel.org; dmarc=pass (policy=none) header.from=kernel.org X-Rspamd-Server: rspam02 X-Stat-Signature: won3urezqxidna9qkf3pmghggsroe7jg X-Rspamd-Queue-Id: B98139001869 X-HE-Tag: 1627655666-37501 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: From: Arnd Bergmann When compat user space asks for more data than the kernel has in its nodemask, get_mempolicy() now either leaks kernel stack data to user space or, if either VMAP_STACK or KASAN are enabled, causes a crash like Unable to handle kernel pointer dereference in virtual kernel address space Failing address: 0000038003e7c000 TEID: 0000038003e7c803 Fault in home space mode while using kernel ASCE. AS:00000001fb388007 R3:000000008021c007 S:0000000082142000 P:0000000000000400 Oops: 0011 ilc:3 [#1] SMP CPU: 0 PID: 1017495 Comm: get_mempolicy Tainted: G OE 5.14.0-20210730.rc3.git0.4ccc9e2db7ac.300.fc34.s390x+next #1 Hardware name: IBM 2827 H66 708 (LPAR) Krnl PSW : 0704e00180000000 00000001f9f11000 (compat_put_bitmap+0x48/0xd0) R:0 T:1 IO:1 EX:1 Key:0 M:1 W:0 P:0 AS:3 CC:2 PM:0 RI:0 EA:3 Krnl GPRS: 0000000000810000 0000000000000000 000000007d9df1c0 0000038003e7c008 0000000000000004 000000007d9df1c4 0000038003e7be40 0000000000010000 0000000000008000 0000000000000000 0000000000000390 00000000000001c8 000000020d6ea000 000002aa00401a48 00000001fa0a85fa 0000038003e7bd50 Krnl Code: 00000001f9f10ff4: a7bb0001 aghi %r11,1 00000001f9f10ff8: 41303008 la %r3,8(%r3) #00000001f9f10ffc: 41502004 la %r5,4(%r2) >00000001f9f11000: e3103ff8ff04 lg %r1,-8(%r3) 00000001f9f11006: 5010f0a4 st %r1,164(%r15) 00000001f9f1100a: a50e0081 llilh %r0,129 00000001f9f1100e: c8402000f0a4 mvcos 0(%r2),164(%r15),%r4 00000001f9f11014: 1799 xr %r9,%r9 Call Trace: [<00000001f9f11000>] compat_put_bitmap+0x48/0xd0 [<00000001fa0a85fa>] kernel_get_mempolicy+0x102/0x178 [<00000001fa0a86b0>] __s390_sys_get_mempolicy+0x40/0x50 [<00000001fa92be30>] __do_syscall+0x1c0/0x1e8 [<00000001fa939148>] system_call+0x78/0xa0 Last Breaking-Event-Address: [<0000038003e7bc00>] 0x38003e7bc00 Kernel panic - not syncing: Fatal exception: panic_on_oops Fix it by copying the correct size in compat mode again. Cc: Heiko Carstens Link: https://lore.kernel.org/lkml/YQPLG20V3dmOfq3a@osiris/ Fixes: (mmotm) mm: simplify compat numa syscalls Signed-off-by: Arnd Bergmann --- mm/mempolicy.c | 1 + 1 file changed, 1 insertion(+) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 4fabf2dddbc0..0d1f3be32723 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1438,6 +1438,7 @@ static int copy_nodes_to_user(unsigned long __user *mask, unsigned long maxnode, if (clear_user((char __user *)mask + nbytes, copy - nbytes)) return -EFAULT; copy = nbytes; + maxnode = nr_node_ids; } if (compat)