Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp15230imm; Fri, 25 May 2018 13:17:16 -0700 (PDT) X-Google-Smtp-Source: AB8JxZpF2U3D7NT5oU0nqRaUJwvU9YX0/BKzm8pAb1NU9ujrOMoGCnHFfoauSsJqnha3709gvQ2O X-Received: by 2002:a65:65c8:: with SMTP id y8-v6mr3149917pgv.320.1527279436469; Fri, 25 May 2018 13:17:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527279436; cv=none; d=google.com; s=arc-20160816; b=UQ/AAwKY9Ol3ysb2x+aalFC9FY1keCDKLYyYWj1N7qwLPhh6znCKJNRQnhd9XG/txp TSEprdbCoPRoxF7A3vyiZ/8ai63M3QFSz97D2wHA/esWxWFbsvNKRvwT5G/OGM+dsS1Q jY3F44zMfU0G/tmzcXuxwlF3uTAHTWnHibYuAeN63/R07im7TD2i5eaB2eeDoFrYUnPL Pacl+s3aiUIYSux/PjafTy8X4Yu3lufxs+13XsW1C6AHmJjxnp8XFyr8/Zg7kIi86nje jNevFlXdbJaHd9r1FaftaFXKarr0iZp+vXov0BhU6WnAV/PDa8fBmJKqpXnSZ6HBxTIC uNBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=q7ifE9Rj2CPfhNfdCa8FkTNJPvE0ZSb5DAVZEYgJzcg=; b=Y1O/15iiYDajfoKRdIGEKf4RLTgjV6symP0sbG12diLDI+vu4FjW+12TiILiLKoZ5T IHRbXAA0w7rSc1ixOwUCFlyMaXCyKpxmxrXIvK5Z6asfVsCXZD14NwJZswPDMcwlufzV 9TfmSwnF/4ozhvML4m3r0dovSWCIg74HluwqoNAPwQpLwE+5WOFkMrckY39iEmIwwc+6 HXoE4VuzjI1qxO4D0Xmiadv7sL9WUGLUS8++MLdvvMwXlq9Uealy6YlGO30I20bbNcZc iBdgs4PSUuPXFY26ZHfpJuxtEQ1YbO37Qd3yePVMPrXS8eTHLH/gY3JHYVPrwGxmVj+E zIPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=jwYRK+1A; 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 b5-v6si2711082plx.4.2018.05.25.13.16.29; Fri, 25 May 2018 13:17:16 -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; dkim=fail header.i=@gmail.com header.s=20161025 header.b=jwYRK+1A; 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 S968206AbeEYUQQ (ORCPT + 99 others); Fri, 25 May 2018 16:16:16 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:33737 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967879AbeEYUQO (ORCPT ); Fri, 25 May 2018 16:16:14 -0400 Received: by mail-qk0-f195.google.com with SMTP id s12-v6so5011718qke.0; Fri, 25 May 2018 13:16:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=q7ifE9Rj2CPfhNfdCa8FkTNJPvE0ZSb5DAVZEYgJzcg=; b=jwYRK+1AdkrTptabEXZQi8/OJC+V6wLU4Od+UhgTnEIoXuCqUeiIptjKvCMHXvYPvV QrZW6yjb60jCK1IatjtGN7s3JnhgJfqX59KKqCoejmGH7z2zbvfWkxHUWEtRsPVDn5UO 1/F7zqqdrMTd7WF0FEOjX5HYH7vJLj23/jn4q8RU/24pUKWaxMsY/eoCkhpRZXDa1UXf 56vCH3MJ2H7jiBkSjggOHXrCn1RI5KwnS6J16EIKcnAhkh9USJngH9fp/ts5kAkVZsoo AtSwbHj8PvmyFDSBZ4JMAr5NGZyP7++ErAGe87gQ29nmVsh+n1VACPdCZfDFBWD3xYme XMPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=q7ifE9Rj2CPfhNfdCa8FkTNJPvE0ZSb5DAVZEYgJzcg=; b=UBaZ1qOhnFkXOBjhkpxpFDFImL6dw5hQjEBmAtxg9MO73aFYArPaEZdukY8AYrZiWc QXUava5QNMmvmlUEkUi7KWnN+d9EB2F+uLFHb9FyKy41zSp/PTrMBYv3HahYG3Ld6JvD 0qJBT9CEqS6HytQY74G7zrAEEbkCvP2FTOojyR43fLwOZxspKrnxAdr7yA9K0Lia40pJ Wsi0q6PZPRbWol7FSq461FTisimp5B2PyZSNChhzFDyQC4lcPHQmyr8Wqb47PUk3cRzx +ZXFR7uSe5gIONQo7vG7WGXpERdF83uviOf0B5GB30HUFj1iuQ7NH29K8PYC3sD0kp4T bAkw== X-Gm-Message-State: ALKqPwfTzs+KsPUi8UaQeR3rRUDsfF7vykpUU4R08R3r8ZguXVVyWr8F MHCby3fTP+pH7ZkOlmc2yL5/kInrDaM2OLxf91I= X-Received: by 2002:a37:c949:: with SMTP id q70-v6mr3451950qki.174.1527279373648; Fri, 25 May 2018 13:16:13 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a0c:b903:0:0:0:0:0 with HTTP; Fri, 25 May 2018 13:16:12 -0700 (PDT) In-Reply-To: References: <20180525151421.2317292-1-arnd@arndb.de> From: Arnd Bergmann Date: Fri, 25 May 2018 22:16:12 +0200 X-Google-Sender-Auth: OOHS2lsZMwca0F_wYEfdy4EPSMo Message-ID: Subject: Re: [PATCH] xfs: mark sb_fname as nonstring To: Eric Sandeen Cc: "Darrick J. Wong" , linux-xfs , Martin Sebor , Brian Foster , Dave Chinner , Eric Sandeen , Dan Williams , Ross Zwisler , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 25, 2018 at 6:53 PM, Eric Sandeen wrote: > 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? My mistake. I tried a few different approaches and ended up using the subject line from an earlier version with a later patch. The 'nonstring' annotation is a variable attribute that gets gcc-8 to shut up about -Wstringop-truncation warnings, and is intended to mark those character arrays that are not expected to be null-terminated but still used with strncpy(). >> 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) :) No idea. Maybe the gcc bug only happens with struct members but not local variables? >> 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? We have an explicit check for that, so I think it's ok: if (len > sizeof(sbp->sb_fname)) return -EINVAL; Arnd