Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3081592rwb; Mon, 15 Aug 2022 17:40:24 -0700 (PDT) X-Google-Smtp-Source: AA6agR5lqcI4hMbdwByTmNaBlve5FEeQzVhksnYF5IN4M0fzd2gZd1+odwrGi8Qb8Otg41QA8951 X-Received: by 2002:a17:906:9b92:b0:730:a237:40fe with SMTP id dd18-20020a1709069b9200b00730a23740femr12155024ejc.464.1660610424476; Mon, 15 Aug 2022 17:40:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660610424; cv=none; d=google.com; s=arc-20160816; b=IqfOEZejl2dIKhhNg7nXLqWmntFG12t+vlWvuKRp9K/Ze+5jHSPS7f9uUoTZnxt4MC MLvUCiHBs3VxAteb4KLnu3IfftbPkD4LezCM1KdH8xxYXXlvt7WmY3fV4WdjEZzHrNT0 SqpHruRc6z+enHURvlZ+BB16/2ntCu7jQw76mmUOZQIMF30I4iamXFtWZv7Z8Z/R2vAd ztRgY1j/He3+gYFY/tK4TaIatY/lbgn8lo0PzeeBZBYUoqTNKkc5wR1qTSzpHYsiiFyi aw52bEG1LsSAuGGC4xKQmdAQNbYI4yLyzeEk4M1yCk2VCv9B6icTp3V+0kg4rFLFb0bC frsg== 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=OLCVhfzP8mIivfbzwcf9MhCT0gXPKeGhs8lkknYd1jQ=; b=WY/SFjBW8UDdx8YEhE6OpgWr5b5MSte1cRxHFXZ8LhzKs63bgSNi7MNv0ClIwdJ/Xb iLAHn25554qS/HCgmDi0MJDcoEBr5tXxYj5j7O8E/PLF8dhFqXA2w34jhRxywx8p7imY dHNyz1IW0Xh+m0bzxhkPJP4OOMNf9SLKOvTsxkg0TnI+UUjDkdtDNTh6sWQztOq8NTwH vIeJ5jvdSEO/i0ZRcdA9AIL9z+ZGXgSUNd9R+ohVWUT7Z1bMnesEulIdarvghZ5iYy2n LtRCFaVrTiI1/+dg4p75hFDRz7/J+NMX1MVVyYq3Ax/ygFhQrodtRqrfNk5mbK0pyEKd m1JA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0QhmSmrW; 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 w6-20020a05640234c600b0043cf66ca11fsi9428646edc.76.2022.08.15.17.39.59; Mon, 15 Aug 2022 17:40:24 -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=0QhmSmrW; 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 S1345598AbiHOV5W (ORCPT + 99 others); Mon, 15 Aug 2022 17:57:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343873AbiHOVzb (ORCPT ); Mon, 15 Aug 2022 17:55:31 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03B9A109A36; Mon, 15 Aug 2022 12:33: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 sin.source.kernel.org (Postfix) with ESMTPS id B9EE4CE12DC; Mon, 15 Aug 2022 19:33:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 946E3C433C1; Mon, 15 Aug 2022 19:33:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592024; bh=fihsa39L0YZmsw9lbsImnQhoGQm4IP/0rXY4b4egfqM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0QhmSmrWMnjW53wXexmtvW0eGPyCL/r1ILiiylHcYQcjOmqbIboNN/wUSthURK6iK 9D8zIP1ocpHJ1Zznetk4YxTKvpCyKqZswh9x3J0Iq6p4n77Mha5g2DFlEdkt83ptLL KarJaB2A08j++flsL2GM5Uly6m+a1BdW0RZfpqvA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Tianyu Li , Arnd Bergmann , Mark Rutland , Andrew Morton , Sasha Levin Subject: [PATCH 5.18 0719/1095] mm/mempolicy: fix get_nodes out of bound access Date: Mon, 15 Aug 2022 20:01:58 +0200 Message-Id: <20220815180459.142421114@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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.1 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,T_SCC_BODY_TEXT_LINE 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: Tianyu Li [ Upstream commit 000eca5d044d1ee23b4ca311793cf3fc528da6c6 ] When user specified more nodes than supported, get_nodes will access nmask array out of bounds. Link: https://lkml.kernel.org/r/20220601093211.2970565-1-tianyu.li@arm.com Fixes: e130242dc351 ("mm: simplify compat numa syscalls") Signed-off-by: Tianyu Li Cc: Arnd Bergmann Cc: Mark Rutland Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- mm/mempolicy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index b27e8d71cda3..c1ccc89845f4 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1387,7 +1387,7 @@ static int get_nodes(nodemask_t *nodes, const unsigned long __user *nmask, unsigned long bits = min_t(unsigned long, maxnode, BITS_PER_LONG); unsigned long t; - if (get_bitmap(&t, &nmask[maxnode / BITS_PER_LONG], bits)) + if (get_bitmap(&t, &nmask[(maxnode - 1) / BITS_PER_LONG], bits)) return -EFAULT; if (maxnode - bits >= MAX_NUMNODES) { -- 2.35.1