Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1273067imm; Tue, 5 Jun 2018 11:46:06 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLnCPZqtzCAHDt7lu2+thsBfXy5oO86z6Bfj87Lt/60Qz/gk5Hl8Ib9o5kz71K3KI/nEOn2 X-Received: by 2002:a65:5106:: with SMTP id f6-v6mr7680248pgq.122.1528224366118; Tue, 05 Jun 2018 11:46:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528224366; cv=none; d=google.com; s=arc-20160816; b=TSP8fT2CUetB4MM4WV91AFmf4L3XfGPtixdPlxxNyihxpjzMZmA37Ay32OZlmhGrap Y80KnfeSUUi8zdnPOgbXTmauVHkOwwWMYitqCVXj8MLs+cD14U0flL0YJT2xKkLMjbYK l+g1OYMWTNYInLiot2Xht6c/Txfp/9BKo2BAl6Jc3EoHDxqqyVvKIZU62Mx4irKDKY9N 5qSIgyQlUj5ijBtu9kXfB3VktFB7MC1YZNXHyTw/6ECL6N2N/q83/OYQzDw/YQVeSLzS shTPbq1rEYgjnNvxnumDZDdlA0HnkQTj5gYzbPwjgJFEAsNTCXvNd9qR2ljUX+kcuB8Z buMA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :arc-authentication-results; bh=FLENJtonso97cElXAp4kYlsPdTxlaZxFQzkS54HX3H4=; b=Eh6R8kPKip8CmYz7b9RASCNTnUD/JWf4psKTe1CnhMQKyUeNDSgGcJNPpGI2lLOiRR BG/6WNGh7xfqNgYJgk/ceXmkHlX9iT7VWcGDUmmakz6rFuyZwQwrQfzvpiXhzfsamNUA jHzNrc+AXwxwjaDxQjS2umhX/rvl/hNUuWUzUcYCxAO5hwajqw6+4oOt5mNvQxRkGNaM +X4l5An+GsyZTtZoj3oxJE8L4OR+3sPCkzHRAsB+k3vGSq33wGzCSFMIyFpXY2Pqod2A oU47DmbmoDXr3EdWuB7ZIFabkrsvjC8SdOzksP5PdJvs9kreBXK9HqUoqxyvFF6cb7xx nCbQ== 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 o73-v6si20548485pfj.118.2018.06.05.11.45.51; Tue, 05 Jun 2018 11:46: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 S1751928AbeFESox (ORCPT + 99 others); Tue, 5 Jun 2018 14:44:53 -0400 Received: from sandeen.net ([63.231.237.45]:37626 "EHLO sandeen.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751786AbeFESot (ORCPT ); Tue, 5 Jun 2018 14:44:49 -0400 Received: from [10.0.0.4] (liberator [10.0.0.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by sandeen.net (Postfix) with ESMTPSA id 73AED78FB; Tue, 5 Jun 2018 13:44:36 -0500 (CDT) Subject: Re: [PATCH] xfs: mark sb_fname as nonstring To: Arnd Bergmann , "Darrick J. Wong" , linux-xfs@vger.kernel.org Cc: Eric Sandeen , Martin Sebor , Brian Foster , Dave Chinner , Dan Williams , Ross Zwisler , linux-kernel@vger.kernel.org References: <20180525151421.2317292-1-arnd@arndb.de> From: Eric Sandeen Openpgp: preference=signencrypt Autocrypt: addr=sandeen@sandeen.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yOSjWuiv4b8vmD3+QFgyvCBxPMdP3xsxN5etheLMO gRwWpLn6yNFq/xtgs+ECgG+gR78yXQyA7iCs5tFs2OrMqV5juSMGmn0kxJUAEQEAAcLBXwQY AQIACQUCTrH31AIbDAAKCRAgrhaS4T3e4BKwD/0ZOOmUNOZCSOLAMjZx3mtYtjYgfUNKi0ki YPveGoRWTqbis8UitPtNrG4XxgzLOijSdOEzQwkdOIp/QnZhGNssMejCnsluK0GQd+RkFVWN mcQT78hBeGcnEMAXZKq7bkIKzvc06GFmkMbX/gAl6DiNGv0UNAX+5FYh+ucCJZSyAp3sA+9/ LKjxnTedX0aygXA6rkpX0Y0FvN/9dfm47+LGq7WAqBOyYTU3E6/+Z72bZoG/cG7ANLxcPool LOrU43oqFnD8QwcN56y4VfFj3/jDF2MX3xu4v2OjglVjMEYHTCxP3mpxesGHuqOit/FR+mF0 MP9JGfj6x+bj/9JMBtCW1bY/aPeMdPGTJvXjGtOVYblGZrSjXRn5++Uuy36CvkcrjuziSDG+ JEexGxczWwN4mrOQWhMT5Jyb+18CO+CWxJfHaYXiLEW7dI1AynL4jjn4W0MSiXpWDUw+fsBO Pk6ah10C4+R1Jc7dyUsKksMfvvhRX1hTIXhth85H16706bneTayZBhlZ/hK18uqTX+s0onG/ m1F3vYvdlE4p2ts1mmixMF7KajN9/E5RQtiSArvKTbfsB6Two4MthIuLuf+M0mI4gPl9SPlf fWCYVPhaU9o83y1KFbD/+lh1pjP7bEu/YudBvz7F2Myjh4/9GUAijrCTNeDTDAgvIJDjXuLX pA== Message-ID: Date: Tue, 5 Jun 2018 13:44:48 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180525151421.2317292-1-arnd@arndb.de> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 5/25/18 10:14 AM, Arnd Bergmann wrote: > 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))) I /think/ this also runs the risk of copying out stack memory. I'll send another proposal based on this with slight modifications. > 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); > > /* >