Skip to content

Commit acf15e0

Browse files
azeemshaikh38kees
authored andcommitted
netfilter: ipset: Replace strlcpy with strscpy
strlcpy() reads the entire source buffer first. This read may exceed the destination size limit. This is both inefficient and can lead to linear read overflows if a source string is not NUL-terminated [1]. In an effort to remove strlcpy() completely [2], replace strlcpy() here with strscpy(). Direct replacement is safe here since return value from all callers of STRLCPY macro were ignored. [1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strlcpy [2] KSPP#89 Signed-off-by: Azeem Shaikh <[email protected]> Acked-by: Jozsef Kadlecsik <[email protected]> Reviewed-by: Kees Cook <[email protected]> Reviewed-by: Simon Horman <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent f0a6b58 commit acf15e0

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

net/netfilter/ipset/ip_set_hash_netiface.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ MODULE_ALIAS("ip_set_hash:net,iface");
4040
#define IP_SET_HASH_WITH_MULTI
4141
#define IP_SET_HASH_WITH_NET0
4242

43-
#define STRLCPY(a, b) strlcpy(a, b, IFNAMSIZ)
43+
#define STRSCPY(a, b) strscpy(a, b, IFNAMSIZ)
4444

4545
/* IPv4 variant */
4646

@@ -182,11 +182,11 @@ hash_netiface4_kadt(struct ip_set *set, const struct sk_buff *skb,
182182

183183
if (!eiface)
184184
return -EINVAL;
185-
STRLCPY(e.iface, eiface);
185+
STRSCPY(e.iface, eiface);
186186
e.physdev = 1;
187187
#endif
188188
} else {
189-
STRLCPY(e.iface, SRCDIR ? IFACE(in) : IFACE(out));
189+
STRSCPY(e.iface, SRCDIR ? IFACE(in) : IFACE(out));
190190
}
191191

192192
if (strlen(e.iface) == 0)
@@ -400,11 +400,11 @@ hash_netiface6_kadt(struct ip_set *set, const struct sk_buff *skb,
400400

401401
if (!eiface)
402402
return -EINVAL;
403-
STRLCPY(e.iface, eiface);
403+
STRSCPY(e.iface, eiface);
404404
e.physdev = 1;
405405
#endif
406406
} else {
407-
STRLCPY(e.iface, SRCDIR ? IFACE(in) : IFACE(out));
407+
STRSCPY(e.iface, SRCDIR ? IFACE(in) : IFACE(out));
408408
}
409409

410410
if (strlen(e.iface) == 0)

0 commit comments

Comments
 (0)