Received: by 10.213.65.68 with SMTP id h4csp2140879imn; Sun, 8 Apr 2018 20:45:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/9dajxKBM0aIF/5+N5s+71wZde+5GSRWY6uTrPCgLEZ1YmnNB5piPGAj83uETdouOZUltx X-Received: by 2002:a17:902:158b:: with SMTP id m11-v6mr36868701pla.300.1523245526974; Sun, 08 Apr 2018 20:45:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523245526; cv=none; d=google.com; s=arc-20160816; b=IDlcOXC5qQ2eKlH8ajRN+FPhip3D+i1CvM5625dp5ktzLA23nWVdR9y9JTT6YQQilq aPqg2MXy+qNpyWAU5QFOHV/xrWoUqjjo59cZ218NVzZRmB+vi+cwSEcPkgld3n3ZLH9W 7tJucC8Y5jL4WPuGNLU+be0CYCxGGbM8Ue+Orjn/44iGiydayY9Sp4Y1STe99oPCmgxv jf30eecrwfTuI4Nn5DHWQHRZGiae4e4SjD/DmDCbOZw6Y1SsaPoReSAkmUingtMm56Rt f3xLvlew3gVkJi6k9vFfaMDdU62UR8DpyLdWxcPWAW2wx54h5YxSGoCmD1PWytzXbf9/ qH4g== 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=xuDeQUPJizf6GBpIvFFKGRrnxR3pvyXRj9XJHPH9DDk=; b=sviJpnkv3oHKyXYhlpfJQpcbDBZ7ij+KInMwcAln1M5lyKXUzklE+CervH4Oiij1gh y0//2zeczmW4CrKjh1e0PDaaoLv8AKbo+kpb1T7N3TW8V/SSi7COk1V5KooMyS+YH2+L /PioqoiNHyL3D8SSlroA/HV4amGZe9ZZ5FZ87Lo39+B2Yv3WelqioCWaJTIB7J1MdFh5 KdTxYPkHCafbdbd+35Uqcc9GkS60wiXkdVcc45M1+J0SY8JJsvSoGZ0sfHXu4ha4TL0o g68oZD4Rqz0M6Hk9XVHcJhv/5VvBe/gqxE/wYVdjOadqJtOizy8bMtV0dxV9g7mPMb/b HGdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=hFr41f4A; 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 t16si11925253pfj.10.2018.04.08.20.44.49; Sun, 08 Apr 2018 20:45:26 -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=hFr41f4A; 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 S1754270AbeDIDkJ (ORCPT + 99 others); Sun, 8 Apr 2018 23:40:09 -0400 Received: from mail-sn1nam01on0114.outbound.protection.outlook.com ([104.47.32.114]:12752 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754363AbeDIAVH (ORCPT ); Sun, 8 Apr 2018 20:21:07 -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=xuDeQUPJizf6GBpIvFFKGRrnxR3pvyXRj9XJHPH9DDk=; b=hFr41f4APNFWJQbDAfHOjmbssv59MQCIq/LdOpCrYCsDM3zIdW1ynGDboUENSqjr0pxHkt7jHPO+cqfgce6sTS4qQ5l20DocqZvcYZcSQ52Fv/PLPmVOUnPhdJ4hPEHvHJU1udeIvlLzZg2tWQTpF6ZEYXpUG9JK4guJSMOdR6Q= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0920.namprd21.prod.outlook.com (52.132.132.165) 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:21:00 +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:21:00 +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.15 157/189] proc: fix /proc/*/map_files lookup Thread-Topic: [PATCH AUTOSEL for 4.15 157/189] proc: fix /proc/*/map_files lookup Thread-Index: AQHTz5hY/86rBVA9YUmabtytGNyUEA== Date: Mon, 9 Apr 2018 00:18:54 +0000 Message-ID: <20180409001637.162453-157-alexander.levin@microsoft.com> References: <20180409001637.162453-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001637.162453-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;DM5PR2101MB0920;7:6PZ3/LBSMbsQi+h2N7mk7aeQ4q7Dwi8IfNOZIlDoMtyaQ/qBzeVVJZo8u2QlUsCihA+T8X4TH/OWV0V3mczdtRU6KoGR2EHxZGxf863qi/o0Q61STDmcBC6iuehjCsJSwn2tLDLCBXdCrd/EMx82Znr+5qOurOMZe7SVKHfH3BFBtI7tKdB3HTdamjj7obA9xlD0987OwiXTZTyqAZEDHzkiL6HjTCzuVCbbj/LmafOoK5ILqAfc0ABap5vwvAyb;20:wT6MF/psnSt8fV7sikvh5JueETulL2QAvbZNo/LbTcJr3FqVCOjILlI9qAR71X6G6njpFE2xm2uSTOzLEE6EtNxzKsf+9joT7qUNIwQ3hk26ZtwSc4ct7+sKc3Kly4q0zl2o64QAJOII7iKfm6akDLvvW0xb21CQ8GiT4hE1QNs= X-MS-Office365-Filtering-Correlation-Id: d685a4ca-81c7-4585-ff27-08d59dafc5ef x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(48565401081)(2017052603328)(7193020);SRVR:DM5PR2101MB0920; x-ms-traffictypediagnostic: DM5PR2101MB0920: 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:DM5PR2101MB0920;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0920; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39860400002)(39380400002)(396003)(366004)(346002)(376002)(199004)(189003)(66066001)(86362001)(59450400001)(3660700001)(3280700002)(25786009)(76176011)(2900100001)(36756003)(6506007)(2906002)(99286004)(86612001)(6486002)(102836004)(305945005)(1076002)(7736002)(97736004)(2616005)(446003)(11346002)(476003)(486006)(26005)(39060400002)(6666003)(6512007)(4326008)(107886003)(6306002)(5660300001)(478600001)(6436002)(105586002)(10290500003)(966005)(5250100002)(22452003)(316002)(186003)(8676002)(110136005)(81166006)(54906003)(6116002)(8936002)(72206003)(53936002)(2501003)(3846002)(68736007)(14454004)(81156014)(10090500001)(106356001)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0920;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: zAOHMxKfg84twvikxW1462kd+HsJvbbEO5mUUtHijvstgLlakAs71kM+edihO+ddG+9UZt99DcOKKR0V244/shAUoTbvwYNZ+v10BBVSlYub8mEEdKLQcDibZA1rLBlgakR2ClN3OA4I4bOcQfcJsE8Rf6KuFktONO49wzRO268a2m91BpiIQ+mUkfy8tbmBG6aezy8UJF8IiUz6wBQi/yGWapNLfkwKB3Kpn8iWlisFrOEXyzwR0VN3FT0mvtpq0xiPbysALjf+3+WL5EMvaQ09n4xyvgUN4fTmRMvYAk09pvBdOMbwyKHRfIdyoBFiT67I7shHJkwFwj3bJg2+CoanOmdDXr7tZqjR4QV2ytlmMuFyBrmPWDpwW+FwoPEDymp0pX9X2Z0jiEAJvkBikz2R95Q01Mk+iS6aIHjCpEI= 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: d685a4ca-81c7-4585-ff27-08d59dafc5ef X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:18:54.5495 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0920 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 60316b52d659..7165e7419bd0 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -100,6 +100,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 @@ -1907,8 +1909,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