From: Eric Sandeen <sandeen@sandeen.net>
To: Arnd Bergmann <arnd@arndb.de>
Cc: "Darrick J. Wong" <darrick.wong@oracle.com>,
linux-xfs <linux-xfs@vger.kernel.org>,
Eric Sandeen <sandeen@redhat.com>,
Martin Sebor <msebor@gmail.com>,
Brian Foster <bfoster@redhat.com>,
Dave Chinner <dchinner@redhat.com>,
Dan Williams <dan.j.williams@intel.com>,
Ross Zwisler <ross.zwisler@linux.intel.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] xfs: mark sb_fname as nonstring
Date: Tue, 5 Jun 2018 16:51:41 -0500 [thread overview]
Message-ID: <b6cfddbc-e643-231c-af73-d1ca686ea057@sandeen.net> (raw)
In-Reply-To: <CAK8P3a1qnvUVN0jF3BYgtyCSNL6gZm8Lc3pg8kVfga5TVN2vTg@mail.gmail.com>
On 6/5/18 4:23 PM, Arnd Bergmann wrote:
> On Tue, Jun 5, 2018 at 8:44 PM, Eric Sandeen <sandeen@sandeen.net> wrote:
>> On 5/25/18 10:14 AM, Arnd Bergmann wrote:
>
>>> 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.
>
> I assumed it's safe since the earlier strncpy() pads the local 'label'
> with zero bytes up the XFSLABEL_MAX, and the last byte
> is explicitly set to guarantee zero padding.
Ah you are right, I forgot that strncpy pads. Did I mention that I hate
C strings... o_O
In that case I suppose your original patch is fine, if you'd like to fix
the "mark as nonstring" subject.
Thanks,
-Eric
next prev parent reply other threads:[~2018-06-05 21:51 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-25 15:14 [PATCH] xfs: mark sb_fname as nonstring Arnd Bergmann
2018-05-25 16:52 ` Christoph Hellwig
2018-05-25 20:18 ` Arnd Bergmann
2018-05-25 16:53 ` Eric Sandeen
2018-05-25 20:16 ` Arnd Bergmann
2018-05-25 20:21 ` Eric Sandeen
2018-06-05 18:44 ` Eric Sandeen
2018-06-05 21:23 ` Arnd Bergmann
2018-06-05 21:51 ` Eric Sandeen [this message]
2018-06-05 19:49 ` [PATCH V2] xfs: fix string handling in get/set functions Eric Sandeen
2018-06-05 21:28 ` Martin Sebor
2018-06-06 2:59 ` Darrick J. Wong
2018-06-06 10:58 ` Christoph Hellwig
2018-06-06 17:45 ` Eric Sandeen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b6cfddbc-e643-231c-af73-d1ca686ea057@sandeen.net \
--to=sandeen@sandeen.net \
--cc=arnd@arndb.de \
--cc=bfoster@redhat.com \
--cc=dan.j.williams@intel.com \
--cc=darrick.wong@oracle.com \
--cc=dchinner@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=msebor@gmail.com \
--cc=ross.zwisler@linux.intel.com \
--cc=sandeen@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox