Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3691778imm; Fri, 25 May 2018 09:53:53 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrz5p493wRVBToz8vbrzVOL/yDqpaYrYrbiH+PcOrt0/07jVM9WAT/24FBeydBryJPHxHjW X-Received: by 2002:a63:a557:: with SMTP id r23-v6mr2653001pgu.336.1527267233554; Fri, 25 May 2018 09:53:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527267233; cv=none; d=google.com; s=arc-20160816; b=NSklDdu6qrYzO5o2s0bDmlarwrGOvw6I1H0X1iNIjhDn5qqTNoID2PFjiwbLQwVqol tgAqVNcFH1Kta9IYoFqZsEafvRQczj5928yVq5Vb9AaaqFIzdrvvnWBKA+z9Wby+yCT6 U7LsojbCTbdaVaYpUo4/qjOQNK0J5009eVIkJDvsVtPZ5JTReo+J/gc77V5w2y54KVS8 baDHkii8JIVFoBo8M2HcbjVV6KaU9AhtONApuZeYyAD3TZ1s+38/tNfWbVzjRGCUU34+ 1B7Xcw6QeqsFzwL/SSZeIRUBdO6PAnU0cAYmLBV/Pu7DQ0x9PN7WYPvkrL86QIwoWK3Q 668Q== 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:from:references:cc:to:subject:arc-authentication-results; bh=qWQwzeFa+NWWgDP6dXbI1jswr7XLWUJguBJ16N4siIY=; b=Edj87do7smDrbsl/NrLGaN16enCltcdv3pAUEMare50rDRZnmFe4N1xP8FviukxCrN Vv5Pb2W7cyEl4aBxTo0zKSWgyqprWJqRK7/uGOTWJCf5FQsbi/Y0Hl/KSHPDPzKowJP2 RTn1Dlc7M7DuFlkYlEkFOLt5Lqky+svXhi049Fw3EcGfjkDdOmFQhS1uS75H1CCA+p58 DXmu+AxgcfIVOlVetf0VQoZophc0lcKn+QHv3yK6JmyKDHxsl7Mfxl54V/+7z8H0iTQG t0sixkaSM9IJtUwWZ0dO5XioOjZLpFZsNIGJWp5ktn+aNGWw/s96bcRLJCickJ9Cd1bd sa9w== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b6-v6si24716857plm.153.2018.05.25.09.53.38; Fri, 25 May 2018 09:53:53 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967343AbeEYQxI (ORCPT + 99 others); Fri, 25 May 2018 12:53:08 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56092 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751057AbeEYQxG (ORCPT ); Fri, 25 May 2018 12:53:06 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 273D6C11F2C1; Fri, 25 May 2018 16:53:06 +0000 (UTC) Received: from [IPv6:::1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1A5D34138; Fri, 25 May 2018 16:53:05 +0000 (UTC) Subject: Re: [PATCH] xfs: mark sb_fname as nonstring To: Arnd Bergmann , "Darrick J. Wong" , linux-xfs@vger.kernel.org Cc: Martin Sebor , Brian Foster , Dave Chinner , Eric Sandeen , Dan Williams , Ross Zwisler , linux-kernel@vger.kernel.org References: <20180525151421.2317292-1-arnd@arndb.de> From: Eric Sandeen Message-ID: Date: Fri, 25 May 2018 11:53:03 -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; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 25 May 2018 16:53:06 +0000 (UTC) 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: Thanks for catching these. The patch summary confuses me, what does "mark sb_fname as nonstring" mean in the context of the actual patch? I hate strings in C! ;) > 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)); ^ o_O hrpmh. > 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. Oops, you are correct. Sigh, I wonder why testing didn't see that. > 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); ok > 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))) ok. (odd how this is ok for copy_to_user but not for strncpy above) :) > 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); Hm but len = strnlen(label, XFSLABEL_MAX + 1); which could be one longer than sbp->sb_fname, no? > spin_unlock(&mp->m_sb_lock); > > /* >