From patchwork Thu Mar 26 00:45:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Randy Dunlap X-Patchwork-Id: 11458941 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 874401392 for ; Thu, 26 Mar 2020 00:45:31 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4AB7020714 for ; Thu, 26 Mar 2020 00:45:31 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="hrCA3qCL" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4AB7020714 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 821956B000A; Wed, 25 Mar 2020 20:45:30 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 7D2806B000C; Wed, 25 Mar 2020 20:45:30 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E6B36B000D; Wed, 25 Mar 2020 20:45:30 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0029.hostedemail.com [216.40.44.29]) by kanga.kvack.org (Postfix) with ESMTP id 540736B000A for ; Wed, 25 Mar 2020 20:45:30 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 314A9181AD0A3 for ; Thu, 26 Mar 2020 00:45:30 +0000 (UTC) X-FDA: 76635670020.12.goose90_4d1c3f0bc1f2a X-Spam-Summary: 2,0,0,4e72e528d84d5265,d41d8cd98f00b204,rdunlap@infradead.org,,RULES_HIT:41:152:355:379:800:854:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1381:1431:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2901:3138:3139:3140:3141:3142:3352:3865:3866:3867:3868:3871:3874:5007:6261:6653:7514:7576:10004:10400:11026:11658:11914:12043:12048:12297:12517:12519:12679:12760:13069:13161:13221:13229:13311:13357:13846:14096:14097:14181:14394:14721:21080:21451:21627:21740:30034:30054:30064:30070,0,RBL:198.137.202.133:@infradead.org:.lbl8.mailshell.net-64.201.201.201 62.8.0.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: goose90_4d1c3f0bc1f2a X-Filterd-Recvd-Size: 3214 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Thu, 26 Mar 2020 00:45:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: Content-Type:In-Reply-To:MIME-Version:Date:Message-ID:From:References:To: Subject:Sender:Reply-To:Cc:Content-ID:Content-Description; bh=MWwomHnbhJIHVLVpUPf/22EMeHWN9bGAPIBVZmcKq3I=; b=hrCA3qCLYzT+ZlkiTVxH2XRaJS 9UGeR5/h64IyIq1GjJh7p1t+oUzr6yrD1h9TxLyNrG9GXJl7fM6Nz02odrprjToUzGMoc2zIC8bCD aaJ7ypDcWXYzm8QdfmWLuqYomZjiTTnL7ni3Do7ao+nlycRe4d4Uhy5RBrW1pE7Zowt23knvKgHhD /+jByArVEDYhsphlLVTlGlBwEw/VQ/Dkn3L5gMpvz4FwYIw7mHVXD+GltYFupfbCEozM1K9Kmf7Ae 6khm/FheGyzoQRflhKzzLrpJTuj1gDkz/ijMNx7ZpZLVwGX0EbmikT6jT+6EQb2MyBEm1bIu35gwR y8+L7Zwg==; Received: from [2601:1c0:6280:3f0::19c2] by bombadil.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jHGeG-00014f-0K; Thu, 26 Mar 2020 00:45:28 +0000 Subject: [PATCH] mm: mempolicy: require at least one nodeid for MPOL_PREFERRED To: Entropy Moe <3ntr0py1337@gmail.com>, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org References: From: Randy Dunlap Message-ID: <89526377-7eb6-b662-e1d8-4430928abde9@infradead.org> Date: Wed, 25 Mar 2020 17:45:26 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-Bogosity: Ham, tests=bogofilter, spamicity=0.000499, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Randy Dunlap Using an empty (malformed) nodelist that is not caught during mount option parsing leads to a stack-out-of-bounds access. The option string that was used was: "mpol=prefer:,". However, MPOL_PREFERRED requires a single node number, which is not being provided here. Add a check that 'nodes' is not empty after parsing for MPOL_PREFERRED's nodeid. Fixes: 095f1fc4ebf3 ("mempolicy: rework shmem mpol parsing and display") Reported-by: Entropy Moe <3ntr0py1337@gmail.com> Signed-off-by: Randy Dunlap Cc: Andrew Morton Cc: linux-mm@kvack.org Cc: Lee Schermerhorn --- mm/mempolicy.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) --- lnx-56-rc6.orig/mm/mempolicy.c +++ lnx-56-rc6/mm/mempolicy.c @@ -2841,7 +2841,9 @@ int mpol_parse_str(char *str, struct mem switch (mode) { case MPOL_PREFERRED: /* - * Insist on a nodelist of one node only + * Insist on a nodelist of one node only, although later + * we use first_node(nodes) to grab a single node, so here + * nodelist (or nodes) cannot be empty. */ if (nodelist) { char *rest = nodelist; @@ -2849,6 +2851,8 @@ int mpol_parse_str(char *str, struct mem rest++; if (*rest) goto out; + if (nodes_empty(nodes)) + goto out; } break; case MPOL_INTERLEAVE: