Skip to content

Commit

Permalink
net: vlan: Avoid using strncpy()
Browse files Browse the repository at this point in the history
Use strscpy_pad() instead of strncpy() which is considered deprecated:
https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings

Signed-off-by: Kees Cook <keescook@chromium.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Kees Cook authored and David S. Miller committed Jun 3, 2021
1 parent 5ff5622 commit 9c153d3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion net/8021q/vlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,8 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)

case GET_VLAN_REALDEV_NAME_CMD:
err = 0;
vlan_dev_get_realdev_name(dev, args.u.device2);
vlan_dev_get_realdev_name(dev, args.u.device2,
sizeof(args.u.device2));
if (copy_to_user(arg, &args,
sizeof(struct vlan_ioctl_args)))
err = -EFAULT;
Expand Down
3 changes: 2 additions & 1 deletion net/8021q/vlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ void vlan_dev_set_ingress_priority(const struct net_device *dev,
int vlan_dev_set_egress_priority(const struct net_device *dev,
u32 skb_prio, u16 vlan_prio);
int vlan_dev_change_flags(const struct net_device *dev, u32 flag, u32 mask);
void vlan_dev_get_realdev_name(const struct net_device *dev, char *result);
void vlan_dev_get_realdev_name(const struct net_device *dev, char *result,
size_t size);

int vlan_check_real_dev(struct net_device *real_dev,
__be16 protocol, u16 vlan_id,
Expand Down
6 changes: 3 additions & 3 deletions net/8021q/vlan_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,9 @@ int vlan_dev_change_flags(const struct net_device *dev, u32 flags, u32 mask)
return 0;
}

void vlan_dev_get_realdev_name(const struct net_device *dev, char *result)
void vlan_dev_get_realdev_name(const struct net_device *dev, char *result, size_t size)
{
strncpy(result, vlan_dev_priv(dev)->real_dev->name, 23);
strscpy_pad(result, vlan_dev_priv(dev)->real_dev->name, size);
}

bool vlan_dev_inherit_address(struct net_device *dev,
Expand Down Expand Up @@ -360,7 +360,7 @@ static int vlan_dev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
struct ifreq ifrr;
int err = -EOPNOTSUPP;

strncpy(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
strscpy_pad(ifrr.ifr_name, real_dev->name, IFNAMSIZ);
ifrr.ifr_ifru = ifr->ifr_ifru;

switch (cmd) {
Expand Down

0 comments on commit 9c153d3

Please sign in to comment.