Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp725441pxb; Mon, 25 Oct 2021 17:32:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwtDl8PKzNt0TbGLTfGlbQ+ZtUozCS9k7NmlZjEP6Dvp5OaG3PE/WF3N1PTfD8nx6dC9nAy X-Received: by 2002:a63:555d:: with SMTP id f29mr16316622pgm.33.1635208325353; Mon, 25 Oct 2021 17:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635208325; cv=none; d=google.com; s=arc-20160816; b=xHOzVsBlLEvDQ8D/atvO/bMkwI35NqNK3vvL2xANHXEoChLzrKCPD++/PhkSWLdv02 Fh/tocZ9J1dySWfcR4AvfXnnJ0Q3DyOOnO/jZ36QIxxIt6+QQ/jOkpVNKKCXBnTGJZDU fs1gLfBrr6yj/ZDWT9T7TEACX3CkLFa09HpIrcsXMa0cBvqiu409grBwEghN16T1SLQt L2o4WUhzcBOs4XRxQnzY8gVQxBAQkIzxeUoNQZQDH55ydX8v3CZQRfao1zBY1TZ0OGwJ MzledRK4ysRTHHKZm/oiz7+LjiHc4QKTqc0DAxuuKJ/nHYJlWnYZqCSbpTpDJ1aEQ9tE fWmw== 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=wW8j82YGxWP6e97DHH5mi0w2qusYsUqB/HqpPlKgudY=; b=hJbSb53CDpHLHZD0RmJpoWC5dyosM/uIUOHARUNYziIAHgJN7+Gzw2+7J2LtBUSp2u uDNwv1uFSItMW49oNYGVPzZo2XueMd+Heb/JxzoGCwLLP0m8L4V6GnGCG2vX0nwcFr1Z 6bGk70709wkFp/BkVCBuD5+QJoKjvRv1vdvtglTdBuroIalfaIbdCeOJ0PjJbnRZtmiG sK4wgtXT/3ZVTuA3zLsYVZ+MAELPkJIdmFn1Pj5rB2TFxmGAeOek24EJ4Yi7w84tuiy8 hZ1/ryxnaXiK857S3nCLRvj0krifFgULkqlzIvgDm2dre225FDa7WnKKgfJbuURCX2EI I1ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sMRtCaox; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j4si27730223pgt.202.2021.10.25.17.31.51; Mon, 25 Oct 2021 17:32:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=sMRtCaox; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S239144AbhJYTyM (ORCPT + 99 others); Mon, 25 Oct 2021 15:54:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:37200 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237428AbhJYTtk (ORCPT ); Mon, 25 Oct 2021 15:49:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1C25361251; Mon, 25 Oct 2021 19:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1635190916; bh=uV89N0vC3aNBinJGFFRnOJN0PftXVKeOCX1Zd4WM3j4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sMRtCaoxfLbF6HbuakQqneALYXhcbBNYubEyIAaY6AwqVAz1Bs0pVSfhsxg0ZngwF wT2+OouNcxR/1wPKXY3Qr0pfsfpgZICBUkA3y+xtiE7EJQPQcMvQnJyakegvQZXZPt qhbfGwrxZiO0o9VA19im0UYJtTxTAiSlow61qxRo= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , Mel Gorman , "Huang, Ying" , Matthew Wilcox , Andrew Morton , Linus Torvalds Subject: [PATCH 5.14 082/169] mm/mempolicy: do not allow illegal MPOL_F_NUMA_BALANCING | MPOL_LOCAL in mbind() Date: Mon, 25 Oct 2021 21:14:23 +0200 Message-Id: <20211025191027.693567597@linuxfoundation.org> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211025191017.756020307@linuxfoundation.org> References: <20211025191017.756020307@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet commit 6d2aec9e123bb9c49cb5c7fc654f25f81e688e8c upstream. syzbot reported access to unitialized memory in mbind() [1] Issue came with commit bda420b98505 ("numa balancing: migrate on fault among multiple bound nodes") This commit added a new bit in MPOL_MODE_FLAGS, but only checked valid combination (MPOL_F_NUMA_BALANCING can only be used with MPOL_BIND) in do_set_mempolicy() This patch moves the check in sanitize_mpol_flags() so that it is also used by mbind() [1] BUG: KMSAN: uninit-value in __mpol_equal+0x567/0x590 mm/mempolicy.c:2260 __mpol_equal+0x567/0x590 mm/mempolicy.c:2260 mpol_equal include/linux/mempolicy.h:105 [inline] vma_merge+0x4a1/0x1e60 mm/mmap.c:1190 mbind_range+0xcc8/0x1e80 mm/mempolicy.c:811 do_mbind+0xf42/0x15f0 mm/mempolicy.c:1333 kernel_mbind mm/mempolicy.c:1483 [inline] __do_sys_mbind mm/mempolicy.c:1490 [inline] __se_sys_mbind+0x437/0xb80 mm/mempolicy.c:1486 __x64_sys_mbind+0x19d/0x200 mm/mempolicy.c:1486 do_syscall_x64 arch/x86/entry/common.c:51 [inline] do_syscall_64+0x54/0xd0 arch/x86/entry/common.c:82 entry_SYSCALL_64_after_hwframe+0x44/0xae Uninit was created at: slab_alloc_node mm/slub.c:3221 [inline] slab_alloc mm/slub.c:3230 [inline] kmem_cache_alloc+0x751/0xff0 mm/slub.c:3235 mpol_new mm/mempolicy.c:293 [inline] do_mbind+0x912/0x15f0 mm/mempolicy.c:1289 kernel_mbind mm/mempolicy.c:1483 [inline] __do_sys_mbind mm/mempolicy.c:1490 [inline] __se_sys_mbind+0x437/0xb80 mm/mempolicy.c:1486 __x64_sys_mbind+0x19d/0x200 mm/mempolicy.c:1486 do_syscall_x64 arch/x86/entry/common.c:51 [inline] do_syscall_64+0x54/0xd0 arch/x86/entry/common.c:82 entry_SYSCALL_64_after_hwframe+0x44/0xae ===================================================== Kernel panic - not syncing: panic_on_kmsan set ... CPU: 0 PID: 15049 Comm: syz-executor.0 Tainted: G B 5.15.0-rc2-syzkaller #0 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:88 [inline] dump_stack_lvl+0x1ff/0x28e lib/dump_stack.c:106 dump_stack+0x25/0x28 lib/dump_stack.c:113 panic+0x44f/0xdeb kernel/panic.c:232 kmsan_report+0x2ee/0x300 mm/kmsan/report.c:186 __msan_warning+0xd7/0x150 mm/kmsan/instrumentation.c:208 __mpol_equal+0x567/0x590 mm/mempolicy.c:2260 mpol_equal include/linux/mempolicy.h:105 [inline] vma_merge+0x4a1/0x1e60 mm/mmap.c:1190 mbind_range+0xcc8/0x1e80 mm/mempolicy.c:811 do_mbind+0xf42/0x15f0 mm/mempolicy.c:1333 kernel_mbind mm/mempolicy.c:1483 [inline] __do_sys_mbind mm/mempolicy.c:1490 [inline] __se_sys_mbind+0x437/0xb80 mm/mempolicy.c:1486 __x64_sys_mbind+0x19d/0x200 mm/mempolicy.c:1486 do_syscall_x64 arch/x86/entry/common.c:51 [inline] do_syscall_64+0x54/0xd0 arch/x86/entry/common.c:82 entry_SYSCALL_64_after_hwframe+0x44/0xae Link: https://lkml.kernel.org/r/20211001215630.810592-1-eric.dumazet@gmail.com Fixes: bda420b98505 ("numa balancing: migrate on fault among multiple bound nodes") Signed-off-by: Eric Dumazet Reported-by: syzbot Acked-by: Mel Gorman Cc: "Huang, Ying" Cc: Matthew Wilcox Cc: Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- mm/mempolicy.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -857,16 +857,6 @@ static long do_set_mempolicy(unsigned sh goto out; } - if (flags & MPOL_F_NUMA_BALANCING) { - if (new && new->mode == MPOL_BIND) { - new->flags |= (MPOL_F_MOF | MPOL_F_MORON); - } else { - ret = -EINVAL; - mpol_put(new); - goto out; - } - } - ret = mpol_set_nodemask(new, nodes, scratch); if (ret) { mpol_put(new); @@ -1450,7 +1440,11 @@ static inline int sanitize_mpol_flags(in return -EINVAL; if ((*flags & MPOL_F_STATIC_NODES) && (*flags & MPOL_F_RELATIVE_NODES)) return -EINVAL; - + if (*flags & MPOL_F_NUMA_BALANCING) { + if (*mode != MPOL_BIND) + return -EINVAL; + *flags |= (MPOL_F_MOF | MPOL_F_MORON); + } return 0; }