Skip to content

Commit

Permalink
rtnetlink: avoid frame size warning in rtnl_newlink()
Browse files Browse the repository at this point in the history
Standard kernel compilation produces the following warning:

net/core/rtnetlink.c: In function ‘rtnl_newlink’:
net/core/rtnetlink.c:3232:1: warning: the frame size of 1288 bytes is larger than 1024 bytes [-Wframe-larger-than=]
 }
  ^

This should not really be an issue, as rtnl_newlink() stack is
generally quite shallow.

Fix the warning by allocating attributes with kmalloc() in a wrapper
and passing it down to rtnl_newlink(), avoiding complexities on error
paths.

Alternatively we could kmalloc() some structure within rtnl_newlink(),
slave attributes look like a good candidate.  In practice it adds to
already rather high complexity and length of the function.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jakub Kicinski authored and David S. Miller committed Nov 30, 2018
1 parent 420d031 commit a293974
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions net/core/rtnetlink.c
Original file line number Diff line number Diff line change
@@ -2971,14 +2971,13 @@ static int rtnl_group_changelink(const struct sk_buff *skb,
return 0;
}

static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
struct netlink_ext_ack *extack)
static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
struct nlattr **attr, struct netlink_ext_ack *extack)
{
struct nlattr *slave_attr[RTNL_SLAVE_MAX_TYPE + 1];
unsigned char name_assign_type = NET_NAME_USER;
struct nlattr *linkinfo[IFLA_INFO_MAX + 1];
const struct rtnl_link_ops *m_ops = NULL;
struct nlattr *attr[RTNL_MAX_TYPE + 1];
struct net_device *master_dev = NULL;
struct net *net = sock_net(skb->sk);
const struct rtnl_link_ops *ops;
@@ -3226,6 +3225,21 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
goto out;
}

static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
struct netlink_ext_ack *extack)
{
struct nlattr **attr;
int ret;

attr = kmalloc_array(RTNL_MAX_TYPE + 1, sizeof(*attr), GFP_KERNEL);
if (!attr)
return -ENOMEM;

ret = __rtnl_newlink(skb, nlh, attr, extack);
kfree(attr);
return ret;
}

static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
struct netlink_ext_ack *extack)
{

0 comments on commit a293974

Please sign in to comment.