From patchwork Wed Jan 15 05:54:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 11333383 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 216AC109A for ; Wed, 15 Jan 2020 05:54:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C66F82467A for ; Wed, 15 Jan 2020 05:54:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="jfHeTIBs" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C66F82467A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id EDA7A8E0005; Wed, 15 Jan 2020 00:54:50 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E8AB18E0003; Wed, 15 Jan 2020 00:54:50 -0500 (EST) 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 D79678E0005; Wed, 15 Jan 2020 00:54:50 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0052.hostedemail.com [216.40.44.52]) by kanga.kvack.org (Postfix) with ESMTP id C07C78E0003 for ; Wed, 15 Jan 2020 00:54:50 -0500 (EST) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 7295A180AD822 for ; Wed, 15 Jan 2020 05:54:50 +0000 (UTC) X-FDA: 76378804740.01.wish94_64618cbfee621 X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,dan.carpenter@oracle.com,:akpm@linux-foundation.org:lee.schermerhorn@hp.com::linux-kernel@vger.kernel.org:syzbot+e64a13c5369a194d67df@syzkaller.appspotmail.com:aarcange@redhat.com:hughd@google.com:mhocko@suse.com:syzkaller-bugs@googlegroups.com:vbabka@suse.cz:viro@zeniv.linux.org.uk:yang.shi@linux.alibaba.com,RULES_HIT:30054:30064:30069:30070,0,RBL:156.151.31.85:@oracle.com:.lbl8.mailshell.net-62.18.0.100 64.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:ft,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:24,LUA_SUMMARY:none X-HE-Tag: wish94_64618cbfee621 X-Filterd-Recvd-Size: 4953 Received: from userp2120.oracle.com (userp2120.oracle.com [156.151.31.85]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Jan 2020 05:54:49 +0000 (UTC) Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 00F5r3Qt081179; Wed, 15 Jan 2020 05:54:45 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=date : from : to : cc : subject : message-id : mime-version : content-type : in-reply-to; s=corp-2019-08-05; bh=1gZPAr1kpJ4E3uZiP+aqnRfB8p5P/qwOcYU0dMQ64EQ=; b=jfHeTIBssvKTq+TbH1r8jsxyu97FsGIelhDNSyahj6GqsHhdo483FQbaDCDKg0XiH9aC liESUFHETLW2pwO6rC3GknaiB6jlXSYLN216WufVP3G44gggE1T8iOR82gaW2CP1zAR+ 9AMjylIuS8kOmk9IHdR5DsjywBmUistEuedYUm9aVhp8sN3fq20j1oe/A97DsmQ5f732 xZdtrAsbxmq63TRiGV+zd967uSJmXvt8e7O/d76Cn4fickPBOC52HuMdCn70MiCl7kDJ uOLVSxYragoZuDhpTF99ZGHoh6Zj7+P0fbPHUnBsosx74qW864iaTZRvXXNBvzftxpPH TQ== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2120.oracle.com with ESMTP id 2xf73yj7tu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Jan 2020 05:54:44 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id 00F5s2cm099491; Wed, 15 Jan 2020 05:54:44 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2xh2sdvmp0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Jan 2020 05:54:44 +0000 Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 00F5sbZs009520; Wed, 15 Jan 2020 05:54:37 GMT Received: from kili.mountain (/129.205.23.165) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 14 Jan 2020 21:54:37 -0800 Date: Wed, 15 Jan 2020 08:54:26 +0300 From: Dan Carpenter To: Andrew Morton , Lee Schermerhorn Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, syzbot , aarcange@redhat.com, hughd@google.com, mhocko@suse.com, syzkaller-bugs@googlegroups.com, vbabka@suse.cz, viro@zeniv.linux.org.uk, yang.shi@linux.alibaba.com Subject: [PATCH] mm/mempolicy.c: Fix out of bounds write in mpol_parse_str() Message-ID: <20200115055426.vdjwvry44nfug7yy@kili.mountain> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <0000000000006a8b8f059c24672a@google.com> X-Mailer: git-send-email haha only kidding User-Agent: NeoMutt/20170113 (1.7.2) X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9500 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-2001150047 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9500 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1911140001 definitions=main-2001150047 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: What we are trying to do is change the '=' character to a NUL terminator and then at the end of the function we restore it back to an '='. The problem is there are two error paths where we jump to the end of the function before we have replaced the '=' with NUL. We end up putting the '=' in the wrong place (possibly one element before the start of the buffer). Reported-by: syzbot+e64a13c5369a194d67df@syzkaller.appspotmail.com Fixes: 095f1fc4ebf3 ("mempolicy: rework shmem mpol parsing and display") Signed-off-by: Dan Carpenter Acked-by: Vlastimil Babka --- mm/mempolicy.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 067cf7d3daf5..1340c5c496b5 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -2817,6 +2817,9 @@ int mpol_parse_str(char *str, struct mempolicy **mpol) char *flags = strchr(str, '='); int err = 1, mode; + if (flags) + *flags++ = '\0'; /* terminate mode string */ + if (nodelist) { /* NUL-terminate mode or flags string */ *nodelist++ = '\0'; @@ -2827,9 +2830,6 @@ int mpol_parse_str(char *str, struct mempolicy **mpol) } else nodes_clear(nodes); - if (flags) - *flags++ = '\0'; /* terminate mode string */ - mode = match_string(policy_modes, MPOL_MAX, str); if (mode < 0) goto out;