Received: by 10.213.65.68 with SMTP id h4csp2120149imn; Sun, 8 Apr 2018 20:12:07 -0700 (PDT) X-Google-Smtp-Source: AIpwx49GR4zUPcD96TOrHg/agnnAiLrzE8jXRFiT3V3j8fd0FI5VGBThGSbHa79zHsB6e3Oans83 X-Received: by 2002:a17:902:5902:: with SMTP id o2-v6mr35907867pli.81.1523243429992; Sun, 08 Apr 2018 20:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523243429; cv=none; d=google.com; s=arc-20160816; b=k81g5bBd6TmdA1sTx4mWMKEi9FeyYzjqRgmqeTAmmoKAR6jgvsJYRByUNJ1MD1KF+V Zlh8mRWxjVl/b5+C5eEuT5INrh7oHLfKUumT7iy3GOVGFESDrU7HZih4Ogd33Cee5Gn1 zJ6j5SGQpJJcYL3Fhjm4m2oc8DTCUKpHnaSq0itwfHL36yZmkPOE9D7cYIs1c+5J6eYM BBAi5qa3VTK/i9QIC2eHMaO0FyGXUQNFMpKAKycOuFhb5uy7oA+GMFIe7Yz2EV1El0oN 7TUFk15KqntPf2yBpWmJKTyDVSHtD4rWWawBowDvQmIa9uxkhn+U8X5AVn9Ma+mCdcW/ czIw== 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=v97pO9OQrNNWhDOJpkk07ZIt3SV4vfNF++F6FrqMha0=; b=y05sPBMxj204SNlawPLhT5ehyqcEU8EJInvVaph3EPvG0I8ZdVmPlls8lIUpWqKBY9 UYSW/7mQGpxPIO0CvFitfZeqUFqA6nhbMIqJK7gschb2s1UYmhVqc1OfarfuY+VphKCS Wmd2g6gpdp9tGphM+FA9zhf5FbL8eRk7XhkTN1VcY/DN9F1MDYf/FPhTRsJYcz0tSu4k T9RXnrK7AcE5zdd9+HDWsnq8ao9nXR6CeGHVzEwV11NCmg0wDSx/sIKlJXWgL6ZV4apZ O2rUduqWaxKnWfRRkHyrmmyO+bflxHAl7lmpHhZSebUaAjDQROOK2Yy6pGkL4wwXWK9D N1uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=o4cAcSx0; 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 x17si2641554pfm.330.2018.04.08.20.09.52; Sun, 08 Apr 2018 20:10:29 -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=o4cAcSx0; 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 S933034AbeDIBnc (ORCPT + 99 others); Sun, 8 Apr 2018 21:43:32 -0400 Received: from mail-bl2nam02on0118.outbound.protection.outlook.com ([104.47.38.118]:14317 "EHLO NAM02-BL2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932509AbeDIAep (ORCPT ); Sun, 8 Apr 2018 20:34:45 -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=v97pO9OQrNNWhDOJpkk07ZIt3SV4vfNF++F6FrqMha0=; b=o4cAcSx0yAy64BySSIm++CVxUGY/m8Tt82qEqhJ6tNkezqJcydZnxFPWdU42WDa2TmzwlthkvGfjYupyqxmQ8LVf8JVTX1A0Sfq2boY+hGzfb8v9Tgu2OhBtgNa/XXDVm7gpJ84Pd/fMtantH8Pdg13KzSKUY2pg+vRrP+p53aw= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0984.namprd21.prod.outlook.com (52.132.133.30) 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:34:40 +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:34:40 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: Alexey Dobriyan , Pavel Emelyanov , Andrei Vagin , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH AUTOSEL for 4.9 279/293] proc: fix /proc/*/map_files lookup Thread-Topic: [PATCH AUTOSEL for 4.9 279/293] proc: fix /proc/*/map_files lookup Thread-Index: AQHTz5lplOOV4TbqMkWpAESxLodEXQ== Date: Mon, 9 Apr 2018 00:26:33 +0000 Message-ID: <20180409002239.163177-279-alexander.levin@microsoft.com> References: <20180409002239.163177-1-alexander.levin@microsoft.com> In-Reply-To: <20180409002239.163177-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;DM5PR2101MB0984;7:23DbLGZSekIBZlIb1kcETcAqDkxq2NkUdgxDPoQna/LOxxb5YyztbHV/+DepGtXAY/l8UBUZXPh1oRPuVNLIpVBTElY6TRUyj/wtWPCid7+RBwbDcV3e0YfuCrZcGVtFo4DVLz0Xf68RBXQ5xBfHUOd3NpInjk2CPzu5M1nXjGLnmKkiFZRKjuZCOIHI2jOJCtiTgnM1BPfZtCIp/3P7lkr+AHcbkZDCBTVTD92w3uZRSWa/HE6COTdywRN5dOE4;20:fVOUOlp4bg3/Gjb88i58o5RQDW7tXibB/UgFs73/fPB4BqsK+3lmuAfu0Ybe9x+S4SljbxgI9RlA234DYmsp1yhJVo9L1IaNlefgzW+j+vnddczaLjY1VYtiiAG3wnpVgCEVNb+RJH6zK5t8D7BA0vzwf0B9u1aLDsPiZZNNwPo= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 11ddc58c-87a2-4555-d0e7-08d59db1ae56 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0984; x-ms-traffictypediagnostic: DM5PR2101MB0984: 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)(85827821059158)(42068640409301); 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:DM5PR2101MB0984;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0984; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(396003)(39860400002)(366004)(39380400002)(346002)(376002)(199004)(189003)(26005)(99286004)(2906002)(14454004)(97736004)(59450400001)(8676002)(81156014)(81166006)(8936002)(6512007)(106356001)(76176011)(186003)(3280700002)(10090500001)(36756003)(6506007)(66066001)(3660700001)(72206003)(478600001)(6666003)(53936002)(2900100001)(105586002)(102836004)(966005)(2501003)(110136005)(54906003)(5250100002)(486006)(1076002)(25786009)(6116002)(6436002)(11346002)(39060400002)(6486002)(22452003)(4326008)(446003)(7736002)(86362001)(305945005)(2616005)(476003)(6306002)(68736007)(3846002)(86612001)(5660300001)(10290500003)(107886003)(316002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0984;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: 5a4LAXDFy77Gx41wUbOuFSzfT8EpBxyGIim9ZvdDFjDD59yXmmMVLCuwQKEAEjbtKH10mGOA6JNP3kPDqP/nP9/UQTPeDlgP3CWtbUf/5xL10Jqdn1Gi5VIqeQTgfgsrrdj7SywhW5eYlYvYz63N+UUOxGY+X1exLq4VNDeP69hAx2BdV1kWwvxgbkqlmiAGf3HK/sJgC92pnxIqC5+zPVJFZ5bXSIrru40snNkkBEycj1M7S3KO2xZNCjF/6yTcRslTPPwjH0hV6Wrr2/pf9XZ2jkRtaCU2CkuC8cuvX4lgqyYd68PPY4pkiW+fh5QGZew+RmKPts1b4GLLVniZT9kjzDt5DZbvLTz8U9fbpkZswXBD8Ya9hyZfeUTLHS38K+jyImfzjzTFUGcGDF4/fb72Gjxb9nm/dueXqPLdrXY= 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: 11ddc58c-87a2-4555-d0e7-08d59db1ae56 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:26:33.9258 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0984 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexey Dobriyan [ Upstream commit ac7f1061c2c11bb8936b1b6a94cdb48de732f7a4 ] Current code does: if (sscanf(dentry->d_name.name, "%lx-%lx", start, end) !=3D 2) However sscanf() is broken garbage. It silently accepts whitespace between format specifiers (did you know that?). It silently accepts valid strings which result in integer overflow. Do not use sscanf() for any even remotely reliable parsing code. OK # readlink '/proc/1/map_files/55a23af39000-55a23b05b000' /lib/systemd/systemd broken # readlink '/proc/1/map_files/ 55a23af39000-55a23b05b000' /lib/systemd/systemd broken # readlink '/proc/1/map_files/55a23af39000-55a23b05b000 ' /lib/systemd/systemd very broken # readlink '/proc/1/map_files/1000000000000000055a23af39000-55a23b05b000' /lib/systemd/systemd Andrei said: : This patch breaks criu. It was a bug in criu. And this bug is on a mino= r : path, which works when memfd_create() isn't available. It is a reason wh= y : I ask to not backport this patch to stable kernels. : : In CRIU this bug can be triggered, only if this patch will be backported : to a kernel which version is lower than v3.16. Link: http://lkml.kernel.org/r/20171120212706.GA14325@avx2 Signed-off-by: Alexey Dobriyan Cc: Pavel Emelyanov Cc: Andrei Vagin Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/proc/base.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index e67fec3c9856..bc7e63d20523 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -94,6 +94,8 @@ #include "internal.h" #include "fd.h" =20 +#include "../../lib/kstrtox.h" + /* NOTE: * Implementing inode permission operations in /proc is almost * certainly an error. Permission checks need to happen during @@ -1864,8 +1866,33 @@ end_instantiate: static int dname_to_vma_addr(struct dentry *dentry, unsigned long *start, unsigned long *end) { - if (sscanf(dentry->d_name.name, "%lx-%lx", start, end) !=3D 2) + const char *str =3D dentry->d_name.name; + unsigned long long sval, eval; + unsigned int len; + + len =3D _parse_integer(str, 16, &sval); + if (len & KSTRTOX_OVERFLOW) + return -EINVAL; + if (sval !=3D (unsigned long)sval) return -EINVAL; + str +=3D len; + + if (*str !=3D '-') + return -EINVAL; + str++; + + len =3D _parse_integer(str, 16, &eval); + if (len & KSTRTOX_OVERFLOW) + return -EINVAL; + if (eval !=3D (unsigned long)eval) + return -EINVAL; + str +=3D len; + + if (*str !=3D '\0') + return -EINVAL; + + *start =3D sval; + *end =3D eval; =20 return 0; } --=20 2.15.1