Received: by 10.223.176.5 with SMTP id f5csp776727wra; Sat, 3 Feb 2018 10:02:18 -0800 (PST) X-Google-Smtp-Source: AH8x224HgWDZQtFbZvsFlVKzs7E108U61cH197fjUnxtYZZmrBlVhIafN+aeIfAtZfAehggsRmg2 X-Received: by 2002:a17:902:d81:: with SMTP id 1-v6mr39657573plv.270.1517680938375; Sat, 03 Feb 2018 10:02:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517680938; cv=none; d=google.com; s=arc-20160816; b=qBIszh8YkdzCP10NQHICviFKVnlpXlLJ4hjelGba/nsma0qeoh8rYiA3y0taFy4T4b npvY6a5YJiPrjLQCRvF+L4Bt8l6eYHNiblBjKAzc8AE5ePXw3F/ElosY3MSY60RxfMcU 0tl6lgE2TAardv/iLyF/FqQEs1JyaOT3wX3yWehtY6sDraA6MACZkrqat9zLoQli4sTK sm4upTCaAt3syfYqxLhw4TGt9EeCBDzb+0nMAPU13WltILHUVLy/7KGZsFssGSEd6JMc +7xGhvqI217o2eTomla8KCKLeF04/Wt9aefTyrshfTh6bDYh3oLgUpXl9s5OO/2QOtsv PYuA== 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=iYRoQZqQhsPjjJ+DL4lggxnulfjr9NTJqMEg4zgHfSo=; b=KrOqzdfXYB5Tn58RSU7D1VP5NIwj9o1yMtsLqzldWgtxnUrHOIT+Q0M0zUaeKIkpV2 sAxS9zipEtscX/GwEw+gRuVDnyyL6xK7yfM4IZ0ygJcj1hErZUaND8IBMg1QXvBUbUA1 up86xf1GnQgaLVkYjBI6JHm43PCkH2RiD3QC4zIMFLEnUD5k/h1DXTEZHJJipSunKIrE kVX4UpdAAVNBWf/vLqu5lafktC80MKHtHoaSZCKHqpZmA4+VfDIIrjgr0YHzQM9PDo4W 7KFrOFFJ1ClPZZKCSFC+Rq2lVJUIc9qyUz7uIU9jIQ7CeqG26F6CvDxKqlIOTngOPBco 3P8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=X1QuL6og; 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 x81si3976436pfe.361.2018.02.03.10.02.02; Sat, 03 Feb 2018 10:02:18 -0800 (PST) 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=X1QuL6og; 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 S1752811AbeBCSAw (ORCPT + 99 others); Sat, 3 Feb 2018 13:00:52 -0500 Received: from mail-bn3nam01on0138.outbound.protection.outlook.com ([104.47.33.138]:24890 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752701AbeBCSAh (ORCPT ); Sat, 3 Feb 2018 13:00:37 -0500 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=iYRoQZqQhsPjjJ+DL4lggxnulfjr9NTJqMEg4zgHfSo=; b=X1QuL6og1QbmYXfyXS1szt/xxep6WhfRJENTGARdodxsWsByYYOw4zD8iUg+bLD7EekD2gHVva3mQwMbtJk1HZB5Jt4u+/Hm6ovU/n3IaVGaDj7F4HN4Rh59nPB/19aiLgn3wS22s19uHMAUZVU4Y4YrWvVxlpFgGqG1lblRyRc= Received: from BL0PR2101MB1027.namprd21.prod.outlook.com (52.132.20.161) by BL0PR2101MB1043.namprd21.prod.outlook.com (52.132.24.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.506.3; Sat, 3 Feb 2018 18:00:27 +0000 Received: from BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9]) by BL0PR2101MB1027.namprd21.prod.outlook.com ([fe80::a8da:b5d9:d710:9bf9%3]) with mapi id 15.20.0485.006; Sat, 3 Feb 2018 18:00:26 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Arnd Bergmann , Alexander Viro , Peter Zijlstra , Serge Hallyn , James Morris , Aleksa Sarai , "Eric W. Biederman" , Frederic Weisbecker , Thomas Gleixner , Andrew Morton , Linus Torvalds , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 002/110] exec: avoid gcc-8 warning for get_task_comm Thread-Topic: [PATCH AUTOSEL for 4.14 002/110] exec: avoid gcc-8 warning for get_task_comm Thread-Index: AQHTnRjeVAhaflsiyEOekqP+FhUEyw== Date: Sat, 3 Feb 2018 18:00:26 +0000 Message-ID: <20180203180015.29073-2-alexander.levin@microsoft.com> References: <20180203180015.29073-1-alexander.levin@microsoft.com> In-Reply-To: <20180203180015.29073-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;BL0PR2101MB1043;7:6XiaaNVSnhoOsQdRLH48DO2u1JGSrAmLX5vQdM+iRQ9fihGDSdOLQjqmSto85mfeVywjZaZKD3YhA+uVhAbBZu/+IjypQ1imPfDvBgK/gRi2oFi1sHO6YkK3L7B+eOCGJ4N1GiFNuSUTy5/MxgNUYkTNFqquMFu1jistdQZurANNUX2FFrT4V8ptE8AYRqgmnGF6rBBtJquL44+JrPwwKYiEjeUAMPiSmEUHnNo6dt1iDH0WXf2CEWGkeh5WVXnL x-ms-exchange-antispam-srfa-diagnostics: SSOS;SSOR; x-forefront-antispam-report: SFV:SKI;SCL:-1;SFV:NSPM;SFS:(10019020)(39380400002)(376002)(39860400002)(366004)(346002)(396003)(189003)(199004)(59450400001)(10290500003)(186003)(6486002)(14454004)(1076002)(102836004)(6306002)(6506007)(76176011)(26005)(6346003)(66066001)(10090500001)(5250100002)(36756003)(6512007)(2501003)(110136005)(99286004)(966005)(54906003)(478600001)(7416002)(53936002)(72206003)(6436002)(316002)(305945005)(7736002)(2950100002)(2906002)(5660300001)(4326008)(106356001)(86362001)(97736004)(25786009)(22452003)(2900100001)(3846002)(107886003)(8676002)(8936002)(6116002)(3280700002)(105586002)(81156014)(81166006)(3660700001)(86612001)(68736007)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:BL0PR2101MB1043;H:BL0PR2101MB1027.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: f589e0f7-e9b0-4a13-ccf8-08d56b300170 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(3008032)(2017052603307)(7193020);SRVR:BL0PR2101MB1043; x-ms-traffictypediagnostic: BL0PR2101MB1043: x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(42068640409301)(146099531331640); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(61425038)(6040501)(2401047)(5005006)(8121501046)(3231101)(2400082)(944501161)(93006095)(93001095)(3002001)(10201501046)(6055026)(61426038)(61427038)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(20161123562045)(20161123564045)(6072148)(201708071742011);SRVR:BL0PR2101MB1043;BCL:0;PCL:0;RULEID:;SRVR:BL0PR2101MB1043; x-forefront-prvs: 05724A8921 received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-message-info: MBbTuUXYRn4qyKd+eaH2bFFr8tMYDIclYvxYKuoaWRVrvXsxb16j6ja+qp8TGGp84VOVgn7a+FltNxAQLvJ/Dg== 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: f589e0f7-e9b0-4a13-ccf8-08d56b300170 X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Feb 2018 18:00:26.4408 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR2101MB1043 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Arnd Bergmann [ Upstream commit 3756f6401c302617c5e091081ca4d26ab604bec5 ] gcc-8 warns about using strncpy() with the source size as the limit: fs/exec.c:1223:32: error: argument to 'sizeof' in 'strncpy' call is the s= ame expression as the source; did you mean to use the size of the destinati= on? [-Werror=3Dsizeof-pointer-memaccess] This is indeed slightly suspicious, as it protects us from source arguments without NUL-termination, but does not guarantee that the destination is terminated. This keeps the strncpy() to ensure we have properly padded target buffer, but ensures that we use the correct length, by passing the actual length of the destination buffer as well as adding a build-time check to ensure it is exactly TASK_COMM_LEN. There are only 23 callsites which I all reviewed to ensure this is currently the case. We could get away with doing only the check or passing the right length, but it doesn't hurt to do both. Link: http://lkml.kernel.org/r/20171205151724.1764896-1-arnd@arndb.de Signed-off-by: Arnd Bergmann Suggested-by: Kees Cook Acked-by: Kees Cook Acked-by: Ingo Molnar Cc: Alexander Viro Cc: Peter Zijlstra Cc: Serge Hallyn Cc: James Morris Cc: Aleksa Sarai Cc: "Eric W. Biederman" Cc: Frederic Weisbecker Cc: Thomas Gleixner Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- fs/exec.c | 7 +++---- include/linux/sched.h | 6 +++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index acec119fcc31..0da4d748b4e6 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1216,15 +1216,14 @@ killed: return -EAGAIN; } =20 -char *get_task_comm(char *buf, struct task_struct *tsk) +char *__get_task_comm(char *buf, size_t buf_size, struct task_struct *tsk) { - /* buf must be at least sizeof(tsk->comm) in size */ task_lock(tsk); - strncpy(buf, tsk->comm, sizeof(tsk->comm)); + strncpy(buf, tsk->comm, buf_size); task_unlock(tsk); return buf; } -EXPORT_SYMBOL_GPL(get_task_comm); +EXPORT_SYMBOL_GPL(__get_task_comm); =20 /* * These functions flushes out all traces of the currently running executa= ble diff --git a/include/linux/sched.h b/include/linux/sched.h index fdf74f27acf1..41354690e4e3 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -1502,7 +1502,11 @@ static inline void set_task_comm(struct task_struct = *tsk, const char *from) __set_task_comm(tsk, from, false); } =20 -extern char *get_task_comm(char *to, struct task_struct *tsk); +extern char *__get_task_comm(char *to, size_t len, struct task_struct *tsk= ); +#define get_task_comm(buf, tsk) ({ \ + BUILD_BUG_ON(sizeof(buf) !=3D TASK_COMM_LEN); \ + __get_task_comm(buf, sizeof(buf), tsk); \ +}) =20 #ifdef CONFIG_SMP void scheduler_ipi(void); --=20 2.11.0