Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3593152imm; Fri, 25 May 2018 08:16:17 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrKhzjtxAhRz4NmqSjTg0NgvbQdwomSJwcvVIslgQW5AZvIKqe5ELN1MiHJhebnDcxzX0bg X-Received: by 2002:a62:fd12:: with SMTP id p18-v6mr2987410pfh.152.1527261377754; Fri, 25 May 2018 08:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527261377; cv=none; d=google.com; s=arc-20160816; b=iWokh/PX3pEvLsLAAelJ7pwZb3U7IsNBVOpxUxklVwLCbNu06zJaE7Ekfo3iXtEetD 7xs13yw8t4M/EYR6CXVzRjEJU820+VUwjY3Yv8HJZrWP0HpelUzoQrCsQVatY0OtALCE eGA+pwLkiUVyy2e+lMI3+FWmp3lWQBkKyE+evnyhQGjk5jq/QyDB+/c7VsCvYyIxZSWw pVmXnDm7KNGWvAXRJOkOtYmMPn5DUvKYrEY/7L8Q+7WLnUdIlAgMBT1NF7VyjDjKV5W+ UeGPGVBmUIi34lAVVOByM2BusBXouuH15arlYa03blLIA/gSeTXJKqVqX81l+vvXsOAT HNfQ== 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=XUz+qP3N5apqm7zvLxWK9k0jHF6O6ShtbsSR1fsfIn0=; b=ECIC7rwgSYF0DmPqoEtK9K17CiTssOv0qU+9CvzwGEkeFrNgBFOrAWBUspRa4MtbhQ dWYO+aTA1Mknhf7DnvfzUUeBmtzWSNuFRY13nzQZdYYGUNIbnEg/y0qHrDAEGarTxP52 aj21VBnH1Veod0LClPuz7/TC3hOxkPaEl7o+kwEnhrKyo/vnusue/LxgNttUvkMiF8Kj KNSuO6mGLyMS3O7FLayDPvImHvEHJ+1FiDYNZ0G65xh2IlligCD5jgJb7M2xL0F4lB5w pmdDEWfZ8DivD7VquT4gdxc5Gsh7rYpzkYpjun+b/fOA3QNGXkwCOUun79UhY8+kWwbl Waxw== 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 q17-v6si23510302pff.301.2018.05.25.08.15.43; Fri, 25 May 2018 08:16:17 -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; 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 S936295AbeEYPPD (ORCPT + 99 others); Fri, 25 May 2018 11:15:03 -0400 Received: from mout.kundenserver.de ([212.227.17.10]:52581 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S936240AbeEYPO6 (ORCPT ); Fri, 25 May 2018 11:14:58 -0400 Received: from wuerfel.lan ([95.208.111.237]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0MWjXP-1fphVf1nFT-00Xv28; Fri, 25 May 2018 17:14:28 +0200 From: Arnd Bergmann To: "Darrick J. Wong" , linux-xfs@vger.kernel.org Cc: Arnd Bergmann , Eric Sandeen , Martin Sebor , Brian Foster , Dave Chinner , Eric Sandeen , Dan Williams , Ross Zwisler , linux-kernel@vger.kernel.org Subject: [PATCH] xfs: mark sb_fname as nonstring Date: Fri, 25 May 2018 17:14:09 +0200 Message-Id: <20180525151421.2317292-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K1:lGmfJXCqxIb8Cn75/TvWJg7ZLDnEMwqMV8Gc8T4Rf0uEWJ1/vnM FmJ33CHgJcYUDAzP5LCmrToA3rDEqe9O6hTQ8d8k7eXQJ7OS+UgejIo+3nm9bj+BO3zvjxk 5ua3ZX3N1i0P0SOLgN4G2/cA0Y4UpG6Wcf56uYJ4OgnMbpxObZHRThPGCn3+Dj2FCqi3sS7 PDJKCX3O29CoryGSGT6cg== X-UI-Out-Filterresults: notjunk:1;V01:K0:O4XavvwYowE=:yMOLKXG5mT5vgrW09iC7iR X/4HkD2oB4CRkoideHg08sCBLKZiokRMIM2iQk169srGhbY4rhqvgzjauGZZIz0mRscXP1dfb EC1WHjqP/dWe2gzD9IvCmOwcCf3rS2RLGZm6swwzoEAN4FnIPBPsoQi375fDaJP1IzAdzicD1 qn2G01yTB8cb8nuduHFaR93Xq3aqwG20RKKv+zbKl7MNORrRqIFhOO1pBBc8Xzeqju837TCBm QVHc8Gr6aJXtVW8p1kurymgZgyVlRl/LtWggSkRFAwFXVEOxtYKbLE1YZs7GVpmc0TnSSYawG U/lIKSUIQ+Bv06RtlooWE7u5y6mzoQWGxmbLOo159EXubrwaRif01qNJ0a3wsgA5F/R1Ao4HQ 2dLwSFcDLBXBQOfgeDEDCaGZ6j2j2gTNf/YhWQMYoDJLnBjekcUJ1pZ3+SFK5qF5lbM5Qkw+1 SoZMKNjbefHRd92ea33pdaJxtoaYgWXy1cZUjFeXfVXgJs1FkebP417mokNfLfR4W/JJnsmS7 7G+E6u1IqV0Xu4L2yZvvJfLx3yNeNtxWREP3u5ILaiu8IvPzf9q91PSN+lTP7reKAIjte8Dv/ fls6K8z8wVA8ghbC6VcR6PKvUz78WTuNNEg6kFdlJmiWXtH4JfR+KQd5CTROBy05+NoRUMJO5 7P/Va1Fd6H6xvWTvfapGxD1QtVtieHgrhzgTZkHTWaIiEx2L+DmSxPpxFZVB10HhSvkA= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org gcc-8 reports two warnings for the newly added getlabel/setlabel code: fs/xfs/xfs_ioctl.c: In function 'xfs_ioc_getlabel': fs/xfs/xfs_ioctl.c:1822:38: 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] strncpy(label, sbp->sb_fname, sizeof(sbp->sb_fname)); ^ In function 'strncpy', inlined from 'xfs_ioc_setlabel' at /git/arm-soc/fs/xfs/xfs_ioctl.c:1863:2, inlined from 'xfs_file_ioctl' at /git/arm-soc/fs/xfs/xfs_ioctl.c:1918:10: include/linux/string.h:254:9: error: '__builtin_strncpy' output may be truncated copying 12 bytes from a string of length 12 [-Werror=stringop-truncation] return __builtin_strncpy(p, q, size); In both cases, part of the problem is that one of the strncpy() arguments is a fixed-length character array with zero-padding rather than a zero-terminated string. In the first one case, we also get an odd warning about sizeof-pointer-memaccess, which doesn't seem right (the sizeof is for an array that happens to be the same as the second strncpy argument). To work around the bogus warning, I use a plain 'XFSLABEL_MAX' for the strncpy() length when copying the label in getlabel. For setlabel(), using memcpy() with the correct length that is already known avoids the second warning and is slightly simpler. In a related issue, it appears that we accidentally skip the trailing \0 when copying a 12-character label back to user space in getlabel(). Using the correct sizeof() argument here copies the extra character. Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85602 Fixes: f7664b31975b ("xfs: implement online get/set fs label") Cc: Eric Sandeen Cc: Martin Sebor Signed-off-by: Arnd Bergmann --- fs/xfs/xfs_ioctl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 84fbf164cbc3..eb79f2bc4dcc 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -1819,12 +1819,12 @@ xfs_ioc_getlabel( BUILD_BUG_ON(sizeof(sbp->sb_fname) > FSLABEL_MAX); spin_lock(&mp->m_sb_lock); - strncpy(label, sbp->sb_fname, sizeof(sbp->sb_fname)); + strncpy(label, sbp->sb_fname, XFSLABEL_MAX); spin_unlock(&mp->m_sb_lock); /* xfs on-disk label is 12 chars, be sure we send a null to user */ label[XFSLABEL_MAX] = '\0'; - if (copy_to_user(user_label, label, sizeof(sbp->sb_fname))) + if (copy_to_user(user_label, label, sizeof(label))) return -EFAULT; return 0; } @@ -1860,7 +1860,7 @@ xfs_ioc_setlabel( spin_lock(&mp->m_sb_lock); memset(sbp->sb_fname, 0, sizeof(sbp->sb_fname)); - strncpy(sbp->sb_fname, label, sizeof(sbp->sb_fname)); + memcpy(sbp->sb_fname, label, len); spin_unlock(&mp->m_sb_lock); /* -- 2.9.0