From mboxrd@z Thu Jan 1 00:00:00 1970 From: Serhey Popovich 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 Message-ID: References: <1513633115-16940-1-git-send-email-serhe.popovych@gmail.com> <20171220.110529.947130105820119272.davem@davemloft.net> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="z453uN8ln7xnwMotfKKN3VerhG0qhDTtZ" Cc: netdev@vger.kernel.org To: David Miller Return-path: Received: from mail-lf0-f68.google.com ([209.85.215.68]:45029 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755583AbdLTTpO (ORCPT ); Wed, 20 Dec 2017 14:45:14 -0500 Received: by mail-lf0-f68.google.com with SMTP id g63so3298997lfl.11 for ; Wed, 20 Dec 2017 11:45:14 -0800 (PST) In-Reply-To: <20171220.110529.947130105820119272.davem@davemloft.net> Sender: netdev-owner@vger.kernel.org List-ID: This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --z453uN8ln7xnwMotfKKN3VerhG0qhDTtZ Content-Type: multipart/mixed; boundary="FAc6j2WedVZFMh2ydXkeqd2fa3rsq9qD7"; protected-headers="v1" From: Serhey Popovich To: David Miller Cc: netdev@vger.kernel.org Message-ID: Subject: Re: [PATCH net-next] dev: Correctly get length of alias string in dev_set_alias() References: <1513633115-16940-1-git-send-email-serhe.popovych@gmail.com> <20171220.110529.947130105820119272.davem@davemloft.net> In-Reply-To: <20171220.110529.947130105820119272.davem@davemloft.net> --FAc6j2WedVZFMh2ydXkeqd2fa3rsq9qD7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable David Miller wrote: > From: Serhey Popovych > Date: Mon, 18 Dec 2017 23:38:35 +0200 >=20 >> 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 >=20 > I don't really see this as useful, really. >=20 > 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. >=20 > 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. >=20 > This therefore just seems to add an new strnlen() unnecessarily to > this code path, which rarely does anything helpful. >=20 > Thanks. >=20 --FAc6j2WedVZFMh2ydXkeqd2fa3rsq9qD7-- --z453uN8ln7xnwMotfKKN3VerhG0qhDTtZ Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.22 (GNU/Linux) iQEcBAEBAgAGBQJaOr24AAoJEBTawMmQ61bBJqoH/06S7iWzggiw95kjN1qyqPx0 Z+h5D1hIU66hMfKthjWiLDWSapl42ukC81hiZNZ1Cyqj4nBjdJ9Ht5bk8EW6hq57 ZM69yeHhZzvuJkgzFTve1HiViz5CvSf3jmAw+fDOEbizrc+5nFfX8QMwnh4UIbnS H9i79gedK+1hlTTQNRcXhGhBq1iWgmMVfNi5AAAg3uRU/sRk0Dz68Dkq64YkFAOh 3BW1x5gDGiow3b6Ozmd22hU3/BVNR71VN2nnHv3ea8Ij3cSm1nx5v5hhwm/ibA+P qPdbAWzS/rmTGqLOQY64tEXkl0kqmxZVB2lBqxkPsVFZms+SCsHsbdHnJFhVw2g= =06jb -----END PGP SIGNATURE----- --z453uN8ln7xnwMotfKKN3VerhG0qhDTtZ--