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: 10090569 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3C1BD60329 for ; Mon, 4 Dec 2017 14:49:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41FCC28DBD for ; Mon, 4 Dec 2017 14:49:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 369B328DC1; Mon, 4 Dec 2017 14:49:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D20CD28DBD for ; Mon, 4 Dec 2017 14:49:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753648AbdLDOt5 (ORCPT ); Mon, 4 Dec 2017 09:49:57 -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-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(-) 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; }