From patchwork Fri May 25 15:14:09 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 136940 Delivered-To: patch@linaro.org Received: by 2002:a2e:9706:0:0:0:0:0 with SMTP id r6-v6csp3717982lji; Fri, 25 May 2018 08:15:06 -0700 (PDT) X-Google-Smtp-Source: AB8JxZp8naIE0B9UAWBpxte6rsQMMwytzyEJ2GDS49T8+D2LEJzK/6OqhRgUaE8C7CNKH3DAR4Ax X-Received: by 2002:a63:69c3:: with SMTP id e186-v6mr2330538pgc.353.1527261306830; Fri, 25 May 2018 08:15:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527261306; cv=none; d=google.com; s=arc-20160816; b=YU7P+SGa1FWWEZj3hAI0NDFTMFXDtdOpF7tsNxk2Gbbf/42FaXoj0H1Ln1l3Rla02r heQCH2pQgeD8nExbh/KyBEa02TjKNlix4ro7+6V6u1xuyWMfE3mCSEZMLnreN9Rxjl3J sDlFJkMDs8mQzezjPTzHP+BgOXtyoibg2B3WLRRGn+86OYflF7EOhiZ4k23OJzUr0vNi WKJa2pH0L84aVpT70h33ZxKQI9fdpWvPhNJ8de3HFd8QYHee9LUPkj1O/T2VrEI+/EU0 nOYMsCwJQclSIhc1Zn9sfgdNkJNcDoufwy1mRBpbGiSOlPkWtMW8055k2L49+OiWVF/e EXgg== 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 203-v6si23589758pfa.60.2018.05.25.08.15.05; Fri, 25 May 2018 08:15:06 -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 S936316AbeEYPPD (ORCPT + 30 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(-) -- 2.9.0 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); /*