Received: by 10.213.65.68 with SMTP id h4csp2123644imn; Sun, 8 Apr 2018 20:17:20 -0700 (PDT) X-Google-Smtp-Source: AIpwx49XYy/Ht2KIdx1ILk7cdb7q+RO0fZhk+WoMoERn+a6X2Gii40MHydJuXdxijqhyRvmH9ph1 X-Received: by 10.99.6.198 with SMTP id 189mr24398698pgg.131.1523243840790; Sun, 08 Apr 2018 20:17:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243840; cv=none; d=google.com; s=arc-20160816; b=c1epQZ0lQshRoCwtajPLbnNro7YQ0QhWx5FwZmv+kcMgG3Gqsaa3SJuZheI0cg9m1G yK+TFZOmGrDvPIOpvGnL7dnlPTGb1hth3C5p2AO9OPUSFJscvN4SBePrpdCbJbLh47T0 KWz/boTW/hWAcf3YD15Iy3LOTs6wTZkmZ+jXOe999lv79o/R8gytrGpacLVYgVXze7K5 br97E5EUBBvEGj+nYbG5UcCgj5Ffxxo1PK+c63CyXY8ib/B9DdiYFoNvTGEnztHpIaQB ddKwupaKmruSPmVuyrwq499tL0UY5kSLx09A9xVN3cN2H6wEhUcXXudjvP9p71VExxqH GlrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=kaApfYsV8hYpl9xyu+olhExU9IR05cH/5NxyxdFo0WY=; b=aret+Li7u6J3z6q1NrySgWWEo/hT4zZiIaKbO20z4W6tZVlgc5h878DLsAjlzARRe5 /cEMeQobOdgWFceT+d5ZLxnfJBdk6VypsgOAVVNh1FR5IzJchlVYHUdvLwo8LEWVP4D3 auIEk1y5iJpgW12cTLW6+GFtjN8cPlVBf494TGrmUH+RjSZOoUdXJ+Pova0PGSucdOay NGHVqv+fiDviJaUMPDUL47/2raWTk1twJOUSxMQRnBga1h7/N3oZlZIV8PlK6lU5Yi/m KczcxbK5qDSNx7y61TqteOOu+qv7yggkoIC5H6KhnVFwbBHPTlLrLpss7mouJ/smIYNv KOQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=e4bXPATZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c1-v6si13715190plo.171.2018.04.08.20.16.43; Sun, 08 Apr 2018 20:17:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=e4bXPATZ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753156AbeDIDFz (ORCPT + 99 others); Sun, 8 Apr 2018 23:05:55 -0400 Received: from mail-sn1nam02on0128.outbound.protection.outlook.com ([104.47.36.128]:23328 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932079AbeDIAYk (ORCPT ); Sun, 8 Apr 2018 20:24:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=kaApfYsV8hYpl9xyu+olhExU9IR05cH/5NxyxdFo0WY=; b=e4bXPATZvHPbnGWkFnhx2BXL09YMApC5rGEDxzYddS4tpKkaMzplEF7D6U1gGm5MOEbzs0ZHR4lQloBZzCHLI71LOm3wdGR8s2C96eEe5ZhBPbvXNyN8EaaJ5Z8riVCx48coCZQvrkP4z2aUZjGGt+5lq/0zNYfyshsM2L2H270= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0983.namprd21.prod.outlook.com (52.132.133.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:24:39 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:24:39 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Yisheng Xie , Andi Kleen , Chris Salls , Christopher Lameter , David Rientjes , Ingo Molnar , Naoya Horiguchi , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 099/161] mm/mempolicy: fix the check of nodemask from user Thread-Topic: [PATCH AUTOSEL for 4.14 099/161] mm/mempolicy: fix the check of nodemask from user Thread-Index: AQHTz5ippxwNN1Ji4EKjY186DnevCg== Date: Mon, 9 Apr 2018 00:21:10 +0000 Message-ID: <20180409001936.162706-99-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0983;7:AMV5mKkvcaCmMOTliuz4RegcHvdZgYO0DdEbGWqcyIe/HoJsX4Zb7YaZMSZmLWRu6eDNPPHrmlU+aYH081uYSuzncuUcK6QcKoTIdAhi9bKrUxe/gsAFrRhEPNqs5Vpt7lDtJQCL6ALWtdxeEvggO89HPSPZamZMQfoP4BXQAt+nCgjLG8TjrQkFjm7M/Gszz7e+kS0JgAZuLc1aNRfiB/7gw67hbDjUMvzE0ovP9X7BzWtUXApJbZ9rXPmg/EWo;20:m3P2wx5tqavAdK28vxesQHiWEF8KxI6hqxxI4SAApuytUSLzWfaKJIdw/UN/AfjWKAoGXStRDy8a3TP5sKzr571A2LsZjBIRH7QU1fwrQL3noFbB2q11VtLLk9Jwr6a23xIVEaq9PrbbD+Q1SztkQGbV/Qdv8dn5BblBM7+Bkgo= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 35bcf1ac-6e15-4846-491f-08d59db04806 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0983; x-ms-traffictypediagnostic: DM5PR2101MB0983: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(50582790962513)(211936372134217)(42068640409301)(153496737603132)(228905959029699); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231221)(944501327)(52105095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0983;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0983; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(346002)(376002)(39380400002)(366004)(199004)(189003)(478600001)(59450400001)(72206003)(10290500003)(3846002)(102836004)(6506007)(6116002)(25786009)(6436002)(66066001)(99286004)(54906003)(86612001)(6666003)(105586002)(53936002)(76176011)(316002)(486006)(7736002)(22452003)(3660700001)(86362001)(97736004)(106356001)(8936002)(110136005)(5660300001)(11346002)(446003)(81166006)(81156014)(2906002)(8676002)(2900100001)(1076002)(476003)(2616005)(7416002)(10090500001)(6486002)(107886003)(36756003)(53376002)(4326008)(966005)(2501003)(68736007)(186003)(305945005)(3280700002)(5250100002)(6306002)(6512007)(26005)(14454004)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0983;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: qNRokQ6B4VtrFUBkq7Oawt6dj4WnZ+BhzcIjyddZJhsVndTumSBy57GDkFGyRpl9A/0OOgTCWZ0BDyaKtqwMW3870AJ6vJyRQ8PG7pqKWghkkMXwJ3FtHCEL9rozlOC1qcVHCBj3Im3+7IjaXq+u4/vNHB1i10A/xKa251jsTbAL+0M9XqmXMWsrtkQwpPOOoJ2WvkhLDzJSEoK2RV0O1Nh+c8gs1ot+1FGvigD4QDumxSb9MiWhtreKdFdcuoiVX/tlDENcff8hc78sSI4png1OkFhiTROmzg+QefOGHLAMsU1sTo881RXSMMZTDgqOEs3beV79wfXE9TNd/6q1xom2JIFPeBZn6sVyMCle7p9nay7HeMOcxJhIA2I1j61H9ZkR0JLQPeYIJZztSgAW1LjEoFsfYueqsumExNay5qk= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 35bcf1ac-6e15-4846-491f-08d59db04806 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:21:10.8938 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0983 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yisheng Xie [ Upstream commit 56521e7a02b7b84a5e72691a1fb15570e6055545 ] As Xiaojun reported the ltp of migrate_pages01 will fail on arm64 system which has 4 nodes[0...3], all have memory and CONFIG_NODES_SHIFT=3D2: migrate_pages01 0 TINFO : test_invalid_nodes migrate_pages01 14 TFAIL : migrate_pages_common.c:45: unexpected fai= lure - returned value =3D 0, expected: -1 migrate_pages01 15 TFAIL : migrate_pages_common.c:55: call succeeded= unexpectedly In this case the test_invalid_nodes of migrate_pages01 will call: SYSC_migrate_pages as: migrate_pages(0, , {0x0000000000000001}, 64, , {0x0000000000000010}, 64) = =3D 0 The new nodes specifies one or more node IDs that are greater than the maximum supported node ID, however, the errno is not set to EINVAL as expected. As man pages of set_mempolicy[1], mbind[2], and migrate_pages[3] mentioned, when nodemask specifies one or more node IDs that are greater than the maximum supported node ID, the errno should set to EINVAL. However, get_nodes only check whether the part of bits [BITS_PER_LONG*BITS_TO_LONGS(MAX_NUMNODES), maxnode) is zero or not, and remain [MAX_NUMNODES, BITS_PER_LONG*BITS_TO_LONGS(MAX_NUMNODES) unchecked. This patch is to check the bits of [MAX_NUMNODES, maxnode) in get_nodes to let migrate_pages set the errno to EINVAL when nodemask specifies one or more node IDs that are greater than the maximum supported node ID, which follows the manpage's guide. [1] http://man7.org/linux/man-pages/man2/set_mempolicy.2.html [2] http://man7.org/linux/man-pages/man2/mbind.2.html [3] http://man7.org/linux/man-pages/man2/migrate_pages.2.html Link: http://lkml.kernel.org/r/1510882624-44342-3-git-send-email-xieyisheng= 1@huawei.com Signed-off-by: Yisheng Xie Reported-by: Tan Xiaojun Acked-by: Vlastimil Babka Cc: Andi Kleen Cc: Chris Salls Cc: Christopher Lameter Cc: David Rientjes Cc: Ingo Molnar Cc: Naoya Horiguchi Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/mempolicy.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index a2af6d58a68f..80b67805b51d 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1262,6 +1262,7 @@ static int get_nodes(nodemask_t *nodes, const unsigne= d long __user *nmask, unsigned long maxnode) { unsigned long k; + unsigned long t; unsigned long nlongs; unsigned long endmask; =20 @@ -1278,13 +1279,19 @@ static int get_nodes(nodemask_t *nodes, const unsig= ned long __user *nmask, else endmask =3D (1UL << (maxnode % BITS_PER_LONG)) - 1; =20 - /* When the user specified more nodes than supported just check - if the non supported part is all zero. */ + /* + * When the user specified more nodes than supported just check + * if the non supported part is all zero. + * + * If maxnode have more longs than MAX_NUMNODES, check + * the bits in that area first. And then go through to + * check the rest bits which equal or bigger than MAX_NUMNODES. + * Otherwise, just check bits [MAX_NUMNODES, maxnode). + */ if (nlongs > BITS_TO_LONGS(MAX_NUMNODES)) { if (nlongs > PAGE_SIZE/sizeof(long)) return -EINVAL; for (k =3D BITS_TO_LONGS(MAX_NUMNODES); k < nlongs; k++) { - unsigned long t; if (get_user(t, nmask + k)) return -EFAULT; if (k =3D=3D nlongs - 1) { @@ -1297,6 +1304,16 @@ static int get_nodes(nodemask_t *nodes, const unsign= ed long __user *nmask, endmask =3D ~0UL; } =20 + if (maxnode > MAX_NUMNODES && MAX_NUMNODES % BITS_PER_LONG !=3D 0) { + unsigned long valid_mask =3D endmask; + + valid_mask &=3D ~((1UL << (MAX_NUMNODES % BITS_PER_LONG)) - 1); + if (get_user(t, nmask + nlongs - 1)) + return -EFAULT; + if (t & valid_mask) + return -EINVAL; + } + if (copy_from_user(nodes_addr(*nodes), nmask, nlongs*sizeof(unsigned long= ))) return -EFAULT; nodes_addr(*nodes)[nlongs-1] &=3D endmask; --=20 2.15.1