Commit a42827b7 authored by Harald Welte's avatar Harald Welte Committed by David S. Miller

[NETFILTER]: cleanup nfnetlink_check_attributes()

1) memset return parameter 'cda' (nfattr pointer array) only on success
2) a message without attributes and just a 'struct nfgenmsg' is valid,
   don't return -EINVAL
3) use likely() and unlikely() where apropriate
Signed-off-by: default avatarHarald Welte <laforge@netfilter.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 927ccbcc
...@@ -164,16 +164,15 @@ nfnetlink_check_attributes(struct nfnetlink_subsystem *subsys, ...@@ -164,16 +164,15 @@ nfnetlink_check_attributes(struct nfnetlink_subsystem *subsys,
return -EINVAL; return -EINVAL;
} }
attr_count = subsys->cb[cb_id].attr_count; min_len = NLMSG_ALIGN(sizeof(struct nfgenmsg));
if (unlikely(nlh->nlmsg_len < min_len))
return -EINVAL;
attr_count = subsys->cb[cb_id].attr_count;
memset(cda, 0, sizeof(struct nfattr *) * attr_count); memset(cda, 0, sizeof(struct nfattr *) * attr_count);
/* check attribute lengths. */ /* check attribute lengths. */
min_len = NLMSG_ALIGN(sizeof(struct nfgenmsg)); if (likely(nlh->nlmsg_len > min_len)) {
if (nlh->nlmsg_len < min_len)
return -EINVAL;
if (nlh->nlmsg_len > min_len) {
struct nfattr *attr = NFM_NFA(NLMSG_DATA(nlh)); struct nfattr *attr = NFM_NFA(NLMSG_DATA(nlh));
int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len); int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
...@@ -186,8 +185,10 @@ nfnetlink_check_attributes(struct nfnetlink_subsystem *subsys, ...@@ -186,8 +185,10 @@ nfnetlink_check_attributes(struct nfnetlink_subsystem *subsys,
} }
attr = NFA_NEXT(attr, attrlen); attr = NFA_NEXT(attr, attrlen);
} }
} else }
return -EINVAL;
/* implicit: if nlmsg_len == min_len, we return 0, and an empty
* (zeroed) cda[] array. The message is valid, but empty. */
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment