Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp801468imu; Tue, 11 Dec 2018 07:48:45 -0800 (PST) X-Google-Smtp-Source: AFSGD/XXQfgIbOVtbQu/4emM66B1S8MEKAA7SS+ehuj6rRdQ7z/GUD/LMaXf5mV8IJwsvyrdSrsp X-Received: by 2002:a17:902:598e:: with SMTP id p14mr16306065pli.260.1544543325728; Tue, 11 Dec 2018 07:48:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544543325; cv=none; d=google.com; s=arc-20160816; b=qIk374VLH2oRxZI5twx4Jj2NNHL74X65g0WCpQweqoHoSsOREzvm5ad7zK+DjC983g CkY486QCfHrTSPaPZMy0sA879ZQ2+sRvvJMXCQrersztIaTo+Wb04oRMo+Bw9Vo62Pxd 7snM3gMb6fgQh//BDxq5M/SQc+Y9qjsQzRV38T472PgHtzGbn7LzvHbpzgW2ARToJd64 9gP2UbVMKcyRBp81y70MBv9xD+mbgGxUPf/nABNvmM02dMCqZHnAjJ6rVVai+6wDCJ3x PRyI70lKFj2uis6ASWZcJEm4fne60csrZ/tljyP06qDBjhjxgwnIQN63Z6Eh2Yb2PXVS Td1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SbtYaCv/zjL5l36ovYSYExIa9rnQY0WDNG6vjQm2WX0=; b=hdCjnbGmP6/AK+qC8ytcaVwrZEyStD63qTwlddsi9/m0Ph3KzCq/h8qVYKe+0kCDM5 V4lbNePCLgTxRTO28qmpoLiQ4GozJ/Kqps3eIJKnBbNaGP2PNcsjulF+s6bvoXW9OgSW h7//Jm6Xxb3dn7bm/Ih5fuyVwHdRHPRYhqHibiMasismurhaMZYsp96TUGVk2Ov8IgG4 t2lMcQm5IENarQmRgTllrAS/dYYR8/YAoEybiSKpcc1hCO52onmD6zUh6PxRHOLk5oGU DigZRFVm/oX9SxEP9CuH/DWtNH6sQGtbTdq/5JO1CkgptnrHDiUUyxZloQGM5SNhk2h1 ciIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=oCRovK+L; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l9si12504033pgj.543.2018.12.11.07.48.31; Tue, 11 Dec 2018 07:48:45 -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=@kernel.org header.s=default header.b=oCRovK+L; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728428AbeLKPqz (ORCPT + 99 others); Tue, 11 Dec 2018 10:46:55 -0500 Received: from mail.kernel.org ([198.145.29.99]:35262 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727048AbeLKPqw (ORCPT ); Tue, 11 Dec 2018 10:46:52 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4C05320989; Tue, 11 Dec 2018 15:46:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1544543212; bh=ctt07fazWbsezFKtq4tR765ojqhyeIjaJUu1KSa68Ds=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oCRovK+LmUcM0mBHWfhoylVCa5Hj7WRkPcJTSJc61pnhpAQ3QuDnGQ65fBlhaObh2 YxXuWwEsU5LzeKS3hyb1IITguLFemFnptvijikRN5hIS3/ug4o3aTQUuaX+P8WfNtm wplIMoqou/jkloxPkFwNp1ruu+Tl19iJQd7PXiX8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Arnd Bergmann , Kees Cook , Ingo Molnar , Alexander Viro , Peter Zijlstra , Serge Hallyn , James Morris , Aleksa Sarai , "Eric W. Biederman" , Frederic Weisbecker , Thomas Gleixner , Andrew Morton , Linus Torvalds Subject: [PATCH 4.4 22/91] exec: avoid gcc-8 warning for get_task_comm Date: Tue, 11 Dec 2018 16:40:41 +0100 Message-Id: <20181211151607.573612833@linuxfoundation.org> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20181211151606.026852373@linuxfoundation.org> References: <20181211151606.026852373@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: Arnd Bergmann commit 3756f6401c302617c5e091081ca4d26ab604bec5 upstream. 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 same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-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: Greg Kroah-Hartman --- fs/exec.c | 7 +++---- include/linux/sched.h | 7 ++++++- 2 files changed, 9 insertions(+), 5 deletions(-) --- a/fs/exec.c +++ b/fs/exec.c @@ -1077,15 +1077,14 @@ killed: return -EAGAIN; } -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); /* * These functions flushes out all traces of the currently running executable --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -2668,7 +2668,12 @@ static inline void set_task_comm(struct { __set_task_comm(tsk, from, false); } -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) != TASK_COMM_LEN); \ + __get_task_comm(buf, sizeof(buf), tsk); \ +}) #ifdef CONFIG_SMP void scheduler_ipi(void);