From: Serhey Popovich <serhe.popovych@gmail.com>
To: David Miller <davem@davemloft.net>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH net-next] dev: Correctly get length of alias string in dev_set_alias()
Date: Wed, 20 Dec 2017 21:44:46 +0200 [thread overview]
Message-ID: <de0b307c-63e7-b786-e9d1-8b4a94f61d9a@gmail.com> (raw)
In-Reply-To: <20171220.110529.947130105820119272.davem@davemloft.net>
[-- Attachment #1.1: Type: text/plain, Size: 1639 bytes --]
David Miller wrote:
> From: Serhey Popovych <serhe.popovych@gmail.com>
> Date: Mon, 18 Dec 2017 23:38:35 +0200
>
>> We supply number of bytes available in @alias via @len
>> parameter to dev_set_alias() which is not the same
>> as zero terminated string length that can be shorter.
>>
>> Both dev_set_alias() users (rtnetlink and sysfs) can
>> submit number of bytes up to IFALIASZ with actual string
>> length slightly shorter by putting '\0' not at @len - 1.
>>
>> Use strnlen() to get length of zero terminated string
>> and not access beyond @len. Correct comment about @len
>> and explain how to unset alias (i.e. use zero for @len).
>>
>> Signed-off-by: Serhey Popovych <serhe.popovych@gmail.com>
>
> I don't really see this as useful, really.
>
> In the sysfs case, we are not presented with a NULL terminated string.
> Instead, the net sysfs code gives us a length that goes up until the
> trailing newline character. The sysfs case is never larger than the
> actual string size + 1.
>
> The netlink attribute is usually sized appropriately for whatever the
> string length actually is.
Sorry but I do not mean larger. I mean shorter. When nla_len() >
strlen() we allocate extra space up to IFALIASZ - 1.
This is definitely fix nothing: we never get above the bounds, but
in case if NULL terminator is in the middle of string with nla_len()
we might allocate unused extra space.
Sorry again if I'm not correct with above assumption.
>
> This therefore just seems to add an new strnlen() unnecessarily to
> this code path, which rarely does anything helpful.
>
> Thanks.
>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 490 bytes --]
next prev parent reply other threads:[~2017-12-20 19:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-18 21:38 [PATCH net-next] dev: Correctly get length of alias string in dev_set_alias() Serhey Popovych
2017-12-20 16:05 ` David Miller
2017-12-20 19:44 ` Serhey Popovich [this message]
2017-12-20 19:55 ` [PATCH net-next] dev: Correctly get length of alias string in dev_set_alias(),Re: " David Miller
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=de0b307c-63e7-b786-e9d1-8b4a94f61d9a@gmail.com \
--to=serhe.popovych@gmail.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/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