diff options
author | Jakub Kicinski <kuba@kernel.org> | 2020-11-16 08:09:50 -0800 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2020-11-16 08:11:05 -0800 |
commit | c0a645a7f94409043b5b1d577590bee9b2ce5333 (patch) | |
tree | e14411f69739118166ce31ae3f307f2ab4b2435c /include/net | |
parent | 41294e6a434d4f19e957c55b275ea0324f275009 (diff) | |
parent | 872f690341948b502c93318f806d821c56772c42 (diff) | |
download | linux-c0a645a7f94409043b5b1d577590bee9b2ce5333.tar.bz2 |
Merge branch 'fix-inefficiences-and-rename-nla_strlcpy'
Francis Laniel says:
====================
Fix inefficiences and rename nla_strlcpy
This patch set answers to first three issues listed in:
https://github.com/KSPP/linux/issues/110
To sum up, the patch contributions are the following:
1. the first patch fixes an inefficiency where some bytes in dst were written
twice, one with 0 the other with src content.
2. The second one modifies nla_strlcpy to return the same value as strscpy,
i.e. number of bytes written or -E2BIG if src was truncated.
It also modifies code that calls nla_strlcpy and checks for its return value.
3. The third renames nla_strlcpy to nla_strscpy.
Unfortunately, I did not find how to create struct nlattr objects so I tested
my modifications on simple char* and with GDB using tc to get to
tcf_proto_check_kind.
====================
Link: https://lore.kernel.org/r/20201115170806.3578-1-laniel_francis@privacyrequired.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'include/net')
-rw-r--r-- | include/net/netlink.h | 4 | ||||
-rw-r--r-- | include/net/pkt_cls.h | 2 |
2 files changed, 3 insertions, 3 deletions
diff --git a/include/net/netlink.h b/include/net/netlink.h index 7356f41d23ba..1ceec518ab49 100644 --- a/include/net/netlink.h +++ b/include/net/netlink.h @@ -142,7 +142,7 @@ * Attribute Misc: * nla_memcpy(dest, nla, count) copy attribute into memory * nla_memcmp(nla, data, size) compare attribute with memory area - * nla_strlcpy(dst, nla, size) copy attribute to a sized string + * nla_strscpy(dst, nla, size) copy attribute to a sized string * nla_strcmp(nla, str) compare attribute with string * * Attribute Parsing: @@ -506,7 +506,7 @@ int __nla_parse(struct nlattr **tb, int maxtype, const struct nlattr *head, struct netlink_ext_ack *extack); int nla_policy_len(const struct nla_policy *, int); struct nlattr *nla_find(const struct nlattr *head, int len, int attrtype); -size_t nla_strlcpy(char *dst, const struct nlattr *nla, size_t dstsize); +ssize_t nla_strscpy(char *dst, const struct nlattr *nla, size_t dstsize); char *nla_strdup(const struct nlattr *nla, gfp_t flags); int nla_memcpy(void *dest, const struct nlattr *src, int count); int nla_memcmp(const struct nlattr *nla, const void *data, size_t size); diff --git a/include/net/pkt_cls.h b/include/net/pkt_cls.h index d4d461236351..133f9ad4d4f9 100644 --- a/include/net/pkt_cls.h +++ b/include/net/pkt_cls.h @@ -512,7 +512,7 @@ tcf_change_indev(struct net *net, struct nlattr *indev_tlv, char indev[IFNAMSIZ]; struct net_device *dev; - if (nla_strlcpy(indev, indev_tlv, IFNAMSIZ) >= IFNAMSIZ) { + if (nla_strscpy(indev, indev_tlv, IFNAMSIZ) < 0) { NL_SET_ERR_MSG_ATTR(extack, indev_tlv, "Interface name too long"); return -EINVAL; |