From patchwork Mon Dec 4 14:49:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 120557 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp4525402qgn; Mon, 4 Dec 2017 06:50:01 -0800 (PST) X-Google-Smtp-Source: AGs4zMYd0LRFTjeG9iKJmEIftQ6YtSsimmVyq1BAMyon/jPXBEVicYrY2TJskW21kriTKGHMaSWq X-Received: by 10.84.128.197 with SMTP id a63mr14669874pla.212.1512399001376; Mon, 04 Dec 2017 06:50:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512399001; cv=none; d=google.com; s=arc-20160816; b=EdCNZu/qy0n+0kEdZqt0wZVrVSj7PO5LHwpCyDtRubFjZi53RiMg84Sfg+MtD+jDtB l9Qwx/cjELKBuKKI7sEhczhsl8ekjsZjJ4ItRQHnIOUyz62l2womzjKP5zHzyKqe0z7c 13kRBGUsoOj9El0iWmc7XiLY3bIj2hop5oe04xlRbEc6DGUfZPa37ts8dZkGFqthGQMp vS235w2TmyGH8zrYGNrND87oUp2VfrWzuYu/3XMwksxuvoesteNYDMFcfPMtoOZZoYcY E+vPpeQ9uQamsGpC/kuu0DlQgjjwjgnNob2Om/0KTvcONCg+yCzGLKWDUy8/UvLSS5e7 FMLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=RiYQ8q7naFlliQ/A8aZsZDr01O95wmeQwS/RlcbTDeI=; b=ZoUdFvDE9Rqd3e/15Iv7nk9jqJGC1IIgAAsiU9+hIJPhu+L7rizK/FeNGqkRye6++a a1uciPRsnaNYVLzTQqbUyzDjFbXXPHNGEvvaO+xnG3cBOOrAeI4Ok7BhEyN1/AeAfSOZ FDHwFc6iw+sw8gwBwyB9dWNLwsQ1JOXApbIhoIlDA1tj1gQ0w3EvSaSjp1gjcxrM9WtV w6MT3fNLIW8G9Js4Z7j5ksEsdQaTrSLUFIlGVu6HmozTPqBIwTrn+9T9XDhuG30AqPAU mIqT2MytbdoYzkAzJig1nBInLo4+Ko2Rs++gCatw6LnBS4V29wG7qati+jPxFi6JAIyE F6RA== ARC-Authentication-Results: i=1; mx.google.com; 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 f66si8441526pfg.412.2017.12.04.06.50.01; Mon, 04 Dec 2017 06:50:01 -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; 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 S1754055AbdLDOuA (ORCPT + 28 others); Mon, 4 Dec 2017 09:50:00 -0500 Received: from mout.kundenserver.de ([212.227.17.13]:54692 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751205AbdLDOtz (ORCPT ); Mon, 4 Dec 2017 09:49:55 -0500 Received: from wuerfel.lan ([149.172.96.106]) by mrelayeu.kundenserver.de (mreue103 [212.227.15.145]) with ESMTPA (Nemesis) id 0MY4Nk-1eYz360RKi-00Urr6; Mon, 04 Dec 2017 15:49:24 +0100 From: Arnd Bergmann To: Alexander Viro Cc: Arnd Bergmann , Kees Cook , Serge Hallyn , James Morris , Ingo Molnar , Andrew Morton , "Eric W. Biederman" , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] exec: avoid gcc-8 warning for get_task_comm Date: Mon, 4 Dec 2017 15:49:04 +0100 Message-Id: <20171204144916.453471-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:IaUFrKChWVWPJgEDdLXuvfKufqCCX75/4kEV0gVHADC487iyBgs rXXqEd1aYKevOQWGEuo3jAc9srivWATu9mTl2t7421c2zEGIQxchmvKPeiolPmAL+kf3KGx T3ZQNhsOMFXtEzsGBkoAPS2DrFPeSNJvfBFM/ljQ9FxrMQiZFKMSoAam1ez3MZzjGarwnAS VbHXTpVd9kT8G1rP59qxA== X-UI-Out-Filterresults: notjunk:1; V01:K0:OFofug04/vk=:QpuseyCsbZNWPh8TuV/Hl5 HyBXzowVJ744pU6+6nB429iENcl1v38Rs/f1OIpR2QJJc46APLxBeApo6mSYQA8wpf/mk/Lkz iRMsMUm9iOssE2KNGX6mtYzYKHol305dVRoXh645D4sD+5axZxqV7obj2EhKtkNHAsZHCnO7n 1CKPnHc0g87J2tYzOLsIp3XGH+Slpr022nWTtC0gJlYGb56qp/A4+e3JRTv+/nPqB3zCCDXf3 AMS3SB7gUcg0+FevXakiet0H60HT+wvIdpU9TLb9RPl9uZfUlDdM59ZR4gCeFzsgwH+UMSQKO Non0Lol3tnkNdW1ajHcBPdPGVPLQCVLlha/j4S7KVhrm42E+hNRhTvmyP519tkJmULO76tWpF vEd2IU7100Cf8iW45qlLQrELcfazeIGA4C7+/Q/1xLAZ9k2eDaS9v4+GbdWy0YQANdoD/HNa7 p56qklW4OOkdALYtQCKR7a2rB8M3OFOu1ByKZNKjt6HGr1yNmqfyikwOy2PZHqP2eRzzNK8wI nW+u7vNFWI8QfGATb5VI1nesH469I06Feiogb8k82UIftE7R1RWxj5wXc22aosx9p06NrcZJG tNF+HC7comM9nLa9HIjM1FRzFSzAIWFSPtRp33kjWy9KnXdA7KbCxyugUvET/6Ep+SWXs1ULi nq4tFOVakw1Qv8fdb7Nd3MuSXxnSGdDNnK3v5UdwrNVMkR0/o1WMErRMDstQw+/2EYMCOYLcU TdmX43Fk57mKBNlqi2UwRKGRVPjPAvC/LM5m9g== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 changes it to strlcpy with a hardcoded length, to guarantee a properly terminated string. Since we already use strlcpy() for __set_task_comm(), the source should always be terminated properly, so this patch won't change the behavior, but make it a bit more robust. Signed-off-by: Arnd Bergmann --- fs/exec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) -- 2.9.0 diff --git a/fs/exec.c b/fs/exec.c index 6be2aa0ab26f..3e8012afe440 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1218,9 +1218,9 @@ static int de_thread(struct task_struct *tsk) char *get_task_comm(char *buf, struct task_struct *tsk) { - /* buf must be at least sizeof(tsk->comm) in size */ + /* buf must be at least TASK_COMM_LEN in size */ task_lock(tsk); - strncpy(buf, tsk->comm, sizeof(tsk->comm)); + strlcpy(buf, tsk->comm, TASK_COMM_LEN); task_unlock(tsk); return buf; }