Commit 627cc4ad authored by Lorenzo Colitti's avatar Lorenzo Colitti Committed by David S. Miller

net: diag: slightly refactor the inet_diag_bc_audit error checks.

This simplifies the code a bit and also allows inet_diag_bc_audit
to send to userspace an error that isn't EINVAL.
Signed-off-by: default avatarLorenzo Colitti <lorenzo@google.com>
Acked-by: default avatarDavid Ahern <dsa@cumulusnetworks.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 9d490b4e
...@@ -706,10 +706,16 @@ static bool valid_port_comparison(const struct inet_diag_bc_op *op, ...@@ -706,10 +706,16 @@ static bool valid_port_comparison(const struct inet_diag_bc_op *op,
return true; return true;
} }
static int inet_diag_bc_audit(const void *bytecode, int bytecode_len) static int inet_diag_bc_audit(const struct nlattr *attr)
{ {
const void *bc = bytecode; const void *bytecode, *bc;
int len = bytecode_len; int bytecode_len, len;
if (!attr || nla_len(attr) < sizeof(struct inet_diag_bc_op))
return -EINVAL;
bytecode = bc = nla_data(attr);
len = bytecode_len = nla_len(attr);
while (len > 0) { while (len > 0) {
int min_len = sizeof(struct inet_diag_bc_op); int min_len = sizeof(struct inet_diag_bc_op);
...@@ -1020,13 +1026,13 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -1020,13 +1026,13 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
if (nlh->nlmsg_flags & NLM_F_DUMP) { if (nlh->nlmsg_flags & NLM_F_DUMP) {
if (nlmsg_attrlen(nlh, hdrlen)) { if (nlmsg_attrlen(nlh, hdrlen)) {
struct nlattr *attr; struct nlattr *attr;
int err;
attr = nlmsg_find_attr(nlh, hdrlen, attr = nlmsg_find_attr(nlh, hdrlen,
INET_DIAG_REQ_BYTECODE); INET_DIAG_REQ_BYTECODE);
if (!attr || err = inet_diag_bc_audit(attr);
nla_len(attr) < sizeof(struct inet_diag_bc_op) || if (err)
inet_diag_bc_audit(nla_data(attr), nla_len(attr))) return err;
return -EINVAL;
} }
{ {
struct netlink_dump_control c = { struct netlink_dump_control c = {
...@@ -1051,13 +1057,13 @@ static int inet_diag_handler_cmd(struct sk_buff *skb, struct nlmsghdr *h) ...@@ -1051,13 +1057,13 @@ static int inet_diag_handler_cmd(struct sk_buff *skb, struct nlmsghdr *h)
h->nlmsg_flags & NLM_F_DUMP) { h->nlmsg_flags & NLM_F_DUMP) {
if (nlmsg_attrlen(h, hdrlen)) { if (nlmsg_attrlen(h, hdrlen)) {
struct nlattr *attr; struct nlattr *attr;
int err;
attr = nlmsg_find_attr(h, hdrlen, attr = nlmsg_find_attr(h, hdrlen,
INET_DIAG_REQ_BYTECODE); INET_DIAG_REQ_BYTECODE);
if (!attr || err = inet_diag_bc_audit(attr);
nla_len(attr) < sizeof(struct inet_diag_bc_op) || if (err)
inet_diag_bc_audit(nla_data(attr), nla_len(attr))) return err;
return -EINVAL;
} }
{ {
struct netlink_dump_control c = { struct netlink_dump_control c = {
......
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