From: Dan Carpenter <dan.carpenter@oracle.com>
To: rdna@fb.com
Cc: kernel-janitors@vger.kernel.org
Subject: [bug report] rtnetlink: Return correct error on changing device netns
Date: Mon, 30 Aug 2021 12:04:06 +0300 [thread overview]
Message-ID: <20210830090405.GA6314@kili> (raw)
Hello Andrey Ignatov,
This is a semi-automatic email about new static checker warnings.
The patch 96a6b93b6988: "rtnetlink: Return correct error on changing
device netns" from Aug 25, 2021, leads to the following Smatch
complaint:
net/core/rtnetlink.c:2698 do_setlink()
error: we previously assumed 'ifname' could be null (see line 2608)
net/core/rtnetlink.c
2607 if (tb[IFLA_NET_NS_PID] || tb[IFLA_NET_NS_FD] || tb[IFLA_TARGET_NETNSID]) {
2608 const char *pat = ifname && ifname[0] ? ifname : NULL;
^^^^^^
The patch adds a new check for if "ifname" is NULL. Is this required?
2609 struct net *net;
2610 int new_ifindex;
2611
2612 net = rtnl_link_get_net_capable(skb, dev_net(dev),
2613 tb, CAP_NET_ADMIN);
2614 if (IS_ERR(net)) {
2615 err = PTR_ERR(net);
2616 goto errout;
2617 }
2618
2619 if (tb[IFLA_NEW_IFINDEX])
2620 new_ifindex = nla_get_s32(tb[IFLA_NEW_IFINDEX]);
2621 else
2622 new_ifindex = 0;
2623
2624 err = __dev_change_net_namespace(dev, net, pat, new_ifindex);
2625 put_net(net);
2626 if (err)
2627 goto errout;
2628 status |= DO_SETLINK_MODIFIED;
2629 }
2630
2631 if (tb[IFLA_MAP]) {
2632 struct rtnl_link_ifmap *u_map;
2633 struct ifmap k_map;
2634
2635 if (!ops->ndo_set_config) {
2636 err = -EOPNOTSUPP;
2637 goto errout;
2638 }
2639
2640 if (!netif_device_present(dev)) {
2641 err = -ENODEV;
2642 goto errout;
2643 }
2644
2645 u_map = nla_data(tb[IFLA_MAP]);
2646 k_map.mem_start = (unsigned long) u_map->mem_start;
2647 k_map.mem_end = (unsigned long) u_map->mem_end;
2648 k_map.base_addr = (unsigned short) u_map->base_addr;
2649 k_map.irq = (unsigned char) u_map->irq;
2650 k_map.dma = (unsigned char) u_map->dma;
2651 k_map.port = (unsigned char) u_map->port;
2652
2653 err = ops->ndo_set_config(dev, &k_map);
2654 if (err < 0)
2655 goto errout;
2656
2657 status |= DO_SETLINK_NOTIFY;
2658 }
2659
2660 if (tb[IFLA_ADDRESS]) {
2661 struct sockaddr *sa;
2662 int len;
2663
2664 len = sizeof(sa_family_t) + max_t(size_t, dev->addr_len,
2665 sizeof(*sa));
2666 sa = kmalloc(len, GFP_KERNEL);
2667 if (!sa) {
2668 err = -ENOMEM;
2669 goto errout;
2670 }
2671 sa->sa_family = dev->type;
2672 memcpy(sa->sa_data, nla_data(tb[IFLA_ADDRESS]),
2673 dev->addr_len);
2674 err = dev_set_mac_address_user(dev, sa, extack);
2675 kfree(sa);
2676 if (err)
2677 goto errout;
2678 status |= DO_SETLINK_MODIFIED;
2679 }
2680
2681 if (tb[IFLA_MTU]) {
2682 err = dev_set_mtu_ext(dev, nla_get_u32(tb[IFLA_MTU]), extack);
2683 if (err < 0)
2684 goto errout;
2685 status |= DO_SETLINK_MODIFIED;
2686 }
2687
2688 if (tb[IFLA_GROUP]) {
2689 dev_set_group(dev, nla_get_u32(tb[IFLA_GROUP]));
2690 status |= DO_SETLINK_NOTIFY;
2691 }
2692
2693 /*
2694 * Interface selected by interface index but interface
2695 * name provided implies that a name change has been
2696 * requested.
2697 */
2698 if (ifm->ifi_index > 0 && ifname[0]) {
^^^^^^^^^
The existing code does not check.
2699 err = dev_change_name(dev, ifname);
2700 if (err < 0)
regards,
dan carpenter
next reply other threads:[~2021-08-30 9:04 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-30 9:04 Dan Carpenter [this message]
2021-08-31 7:06 ` [bug report] rtnetlink: Return correct error on changing device netns Andrey Ignatov
2021-08-31 9:03 ` Dan Carpenter
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=20210830090405.GA6314@kili \
--to=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=rdna@fb.com \
/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;
as well as URLs for NNTP newsgroup(s).