提交 1d00a4eb 编写于 作者: T Thomas Graf 提交者: David S. Miller

[NETLINK]: Remove error pointer from netlink message handler

The error pointer argument in netlink message handlers is used
to signal the special case where processing has to be interrupted
because a dump was started but no error happened. Instead it is
simpler and more clear to return -EINTR and have netlink_run_queue()
deal with getting the queue right.

nfnetlink passed on this error pointer to its subsystem handlers
but only uses it to signal the start of a netlink dump. Therefore
it can be removed there as well.

This patch also cleans up the error handling in the affected
message handlers to be consistent since it had to be touched anyway.
Signed-off-by: NThomas Graf <tgraf@suug.ch>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 45e7ae7f
...@@ -111,7 +111,7 @@ struct nfgenmsg { ...@@ -111,7 +111,7 @@ struct nfgenmsg {
struct nfnl_callback struct nfnl_callback
{ {
int (*call)(struct sock *nl, struct sk_buff *skb, int (*call)(struct sock *nl, struct sk_buff *skb,
struct nlmsghdr *nlh, struct nfattr *cda[], int *errp); struct nlmsghdr *nlh, struct nfattr *cda[]);
u_int16_t attr_count; /* number of nfattr's */ u_int16_t attr_count; /* number of nfattr's */
}; };
......
...@@ -214,7 +214,7 @@ struct nl_info { ...@@ -214,7 +214,7 @@ struct nl_info {
extern void netlink_run_queue(struct sock *sk, unsigned int *qlen, extern void netlink_run_queue(struct sock *sk, unsigned int *qlen,
int (*cb)(struct sk_buff *, int (*cb)(struct sk_buff *,
struct nlmsghdr *, int *)); struct nlmsghdr *));
extern void netlink_queue_skip(struct nlmsghdr *nlh, extern void netlink_queue_skip(struct nlmsghdr *nlh,
struct sk_buff *skb); struct sk_buff *skb);
extern int nlmsg_notify(struct sock *sk, struct sk_buff *skb, extern int nlmsg_notify(struct sock *sk, struct sk_buff *skb,
......
...@@ -852,8 +852,7 @@ static int rtattr_max; ...@@ -852,8 +852,7 @@ static int rtattr_max;
/* Process one rtnetlink message. */ /* Process one rtnetlink message. */
static __inline__ int static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp)
{ {
rtnl_doit_func doit; rtnl_doit_func doit;
int sz_idx, kind; int sz_idx, kind;
...@@ -863,10 +862,8 @@ rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp) ...@@ -863,10 +862,8 @@ rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp)
int err; int err;
type = nlh->nlmsg_type; type = nlh->nlmsg_type;
/* Unknown message: reply with EINVAL */
if (type > RTM_MAX) if (type > RTM_MAX)
goto err_inval; return -EINVAL;
type -= RTM_BASE; type -= RTM_BASE;
...@@ -875,40 +872,33 @@ rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp) ...@@ -875,40 +872,33 @@ rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp)
return 0; return 0;
family = ((struct rtgenmsg*)NLMSG_DATA(nlh))->rtgen_family; family = ((struct rtgenmsg*)NLMSG_DATA(nlh))->rtgen_family;
if (family >= NPROTO) { if (family >= NPROTO)
*errp = -EAFNOSUPPORT; return -EAFNOSUPPORT;
return -1;
}
sz_idx = type>>2; sz_idx = type>>2;
kind = type&3; kind = type&3;
if (kind != 2 && security_netlink_recv(skb, CAP_NET_ADMIN)) { if (kind != 2 && security_netlink_recv(skb, CAP_NET_ADMIN))
*errp = -EPERM; return -EPERM;
return -1;
}
if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) { if (kind == 2 && nlh->nlmsg_flags&NLM_F_DUMP) {
rtnl_dumpit_func dumpit; rtnl_dumpit_func dumpit;
dumpit = rtnl_get_dumpit(family, type); dumpit = rtnl_get_dumpit(family, type);
if (dumpit == NULL) if (dumpit == NULL)
goto err_inval; return -EINVAL;
if ((*errp = netlink_dump_start(rtnl, skb, nlh,
dumpit, NULL)) != 0) {
return -1;
}
netlink_queue_skip(nlh, skb); err = netlink_dump_start(rtnl, skb, nlh, dumpit, NULL);
return -1; if (err == 0)
err = -EINTR;
return err;
} }
memset(rta_buf, 0, (rtattr_max * sizeof(struct rtattr *))); memset(rta_buf, 0, (rtattr_max * sizeof(struct rtattr *)));
min_len = rtm_min[sz_idx]; min_len = rtm_min[sz_idx];
if (nlh->nlmsg_len < min_len) if (nlh->nlmsg_len < min_len)
goto err_inval; return -EINVAL;
if (nlh->nlmsg_len > min_len) { if (nlh->nlmsg_len > min_len) {
int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len); int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
...@@ -918,7 +908,7 @@ rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp) ...@@ -918,7 +908,7 @@ rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp)
unsigned flavor = attr->rta_type; unsigned flavor = attr->rta_type;
if (flavor) { if (flavor) {
if (flavor > rta_max[sz_idx]) if (flavor > rta_max[sz_idx])
goto err_inval; return -EINVAL;
rta_buf[flavor-1] = attr; rta_buf[flavor-1] = attr;
} }
attr = RTA_NEXT(attr, attrlen); attr = RTA_NEXT(attr, attrlen);
...@@ -927,15 +917,9 @@ rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp) ...@@ -927,15 +917,9 @@ rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp)
doit = rtnl_get_doit(family, type); doit = rtnl_get_doit(family, type);
if (doit == NULL) if (doit == NULL)
goto err_inval; return -EINVAL;
err = doit(skb, nlh, (void *)&rta_buf[0]);
*errp = err;
return err;
err_inval: return doit(skb, nlh, (void *)&rta_buf[0]);
*errp = -EINVAL;
return -1;
} }
static void rtnetlink_rcv(struct sock *sk, int len) static void rtnetlink_rcv(struct sock *sk, int len)
......
...@@ -661,7 +661,7 @@ static const size_t cta_min[CTA_MAX] = { ...@@ -661,7 +661,7 @@ static const size_t cta_min[CTA_MAX] = {
static int static int
ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb, ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) struct nlmsghdr *nlh, struct nfattr *cda[])
{ {
struct nf_conntrack_tuple_hash *h; struct nf_conntrack_tuple_hash *h;
struct nf_conntrack_tuple tuple; struct nf_conntrack_tuple tuple;
...@@ -709,7 +709,7 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb, ...@@ -709,7 +709,7 @@ ctnetlink_del_conntrack(struct sock *ctnl, struct sk_buff *skb,
static int static int
ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb, ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) struct nlmsghdr *nlh, struct nfattr *cda[])
{ {
struct nf_conntrack_tuple_hash *h; struct nf_conntrack_tuple_hash *h;
struct nf_conntrack_tuple tuple; struct nf_conntrack_tuple tuple;
...@@ -720,22 +720,15 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb, ...@@ -720,22 +720,15 @@ ctnetlink_get_conntrack(struct sock *ctnl, struct sk_buff *skb,
int err = 0; int err = 0;
if (nlh->nlmsg_flags & NLM_F_DUMP) { if (nlh->nlmsg_flags & NLM_F_DUMP) {
u32 rlen;
#ifndef CONFIG_NF_CT_ACCT #ifndef CONFIG_NF_CT_ACCT
if (NFNL_MSG_TYPE(nlh->nlmsg_type) == IPCTNL_MSG_CT_GET_CTRZERO) if (NFNL_MSG_TYPE(nlh->nlmsg_type) == IPCTNL_MSG_CT_GET_CTRZERO)
return -ENOTSUPP; return -ENOTSUPP;
#endif #endif
if ((*errp = netlink_dump_start(ctnl, skb, nlh, err = netlink_dump_start(ctnl, skb, nlh, ctnetlink_dump_table,
ctnetlink_dump_table, ctnetlink_done);
ctnetlink_done)) != 0) if (err == 0)
return -EINVAL; err = -EINTR;
return err;
rlen = NLMSG_ALIGN(nlh->nlmsg_len);
if (rlen > skb->len)
rlen = skb->len;
skb_pull(skb, rlen);
return 0;
} }
if (nfattr_bad_size(cda, CTA_MAX, cta_min)) if (nfattr_bad_size(cda, CTA_MAX, cta_min))
...@@ -1009,7 +1002,7 @@ ctnetlink_create_conntrack(struct nfattr *cda[], ...@@ -1009,7 +1002,7 @@ ctnetlink_create_conntrack(struct nfattr *cda[],
static int static int
ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb, ctnetlink_new_conntrack(struct sock *ctnl, struct sk_buff *skb,
struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) struct nlmsghdr *nlh, struct nfattr *cda[])
{ {
struct nf_conntrack_tuple otuple, rtuple; struct nf_conntrack_tuple otuple, rtuple;
struct nf_conntrack_tuple_hash *h = NULL; struct nf_conntrack_tuple_hash *h = NULL;
...@@ -1260,7 +1253,7 @@ static const size_t cta_min_exp[CTA_EXPECT_MAX] = { ...@@ -1260,7 +1253,7 @@ static const size_t cta_min_exp[CTA_EXPECT_MAX] = {
static int static int
ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb, ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) struct nlmsghdr *nlh, struct nfattr *cda[])
{ {
struct nf_conntrack_tuple tuple; struct nf_conntrack_tuple tuple;
struct nf_conntrack_expect *exp; struct nf_conntrack_expect *exp;
...@@ -1273,17 +1266,12 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb, ...@@ -1273,17 +1266,12 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
return -EINVAL; return -EINVAL;
if (nlh->nlmsg_flags & NLM_F_DUMP) { if (nlh->nlmsg_flags & NLM_F_DUMP) {
u32 rlen; err = netlink_dump_start(ctnl, skb, nlh,
ctnetlink_exp_dump_table,
if ((*errp = netlink_dump_start(ctnl, skb, nlh, ctnetlink_done);
ctnetlink_exp_dump_table, if (err == 0)
ctnetlink_done)) != 0) err = -EINTR;
return -EINVAL; return err;
rlen = NLMSG_ALIGN(nlh->nlmsg_len);
if (rlen > skb->len)
rlen = skb->len;
skb_pull(skb, rlen);
return 0;
} }
if (cda[CTA_EXPECT_MASTER-1]) if (cda[CTA_EXPECT_MASTER-1])
...@@ -1330,7 +1318,7 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb, ...@@ -1330,7 +1318,7 @@ ctnetlink_get_expect(struct sock *ctnl, struct sk_buff *skb,
static int static int
ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb, ctnetlink_del_expect(struct sock *ctnl, struct sk_buff *skb,
struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) struct nlmsghdr *nlh, struct nfattr *cda[])
{ {
struct nf_conntrack_expect *exp, *tmp; struct nf_conntrack_expect *exp, *tmp;
struct nf_conntrack_tuple tuple; struct nf_conntrack_tuple tuple;
...@@ -1464,7 +1452,7 @@ ctnetlink_create_expect(struct nfattr *cda[], u_int8_t u3) ...@@ -1464,7 +1452,7 @@ ctnetlink_create_expect(struct nfattr *cda[], u_int8_t u3)
static int static int
ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb, ctnetlink_new_expect(struct sock *ctnl, struct sk_buff *skb,
struct nlmsghdr *nlh, struct nfattr *cda[], int *errp) struct nlmsghdr *nlh, struct nfattr *cda[])
{ {
struct nf_conntrack_tuple tuple; struct nf_conntrack_tuple tuple;
struct nf_conntrack_expect *exp; struct nf_conntrack_expect *exp;
......
...@@ -195,17 +195,14 @@ int nfnetlink_unicast(struct sk_buff *skb, u_int32_t pid, int flags) ...@@ -195,17 +195,14 @@ int nfnetlink_unicast(struct sk_buff *skb, u_int32_t pid, int flags)
EXPORT_SYMBOL_GPL(nfnetlink_unicast); EXPORT_SYMBOL_GPL(nfnetlink_unicast);
/* Process one complete nfnetlink message. */ /* Process one complete nfnetlink message. */
static int nfnetlink_rcv_msg(struct sk_buff *skb, static int nfnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
struct nlmsghdr *nlh, int *errp)
{ {
struct nfnl_callback *nc; struct nfnl_callback *nc;
struct nfnetlink_subsystem *ss; struct nfnetlink_subsystem *ss;
int type, err = 0; int type, err;
if (security_netlink_recv(skb, CAP_NET_ADMIN)) { if (security_netlink_recv(skb, CAP_NET_ADMIN))
*errp = -EPERM; return -EPERM;
return -1;
}
/* Only requests are handled by kernel now. */ /* Only requests are handled by kernel now. */
if (!(nlh->nlmsg_flags & NLM_F_REQUEST)) if (!(nlh->nlmsg_flags & NLM_F_REQUEST))
...@@ -227,12 +224,12 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, ...@@ -227,12 +224,12 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb,
ss = nfnetlink_get_subsys(type); ss = nfnetlink_get_subsys(type);
if (!ss) if (!ss)
#endif #endif
goto err_inval; return -EINVAL;
} }
nc = nfnetlink_find_client(type, ss); nc = nfnetlink_find_client(type, ss);
if (!nc) if (!nc)
goto err_inval; return -EINVAL;
{ {
u_int16_t attr_count = u_int16_t attr_count =
...@@ -243,16 +240,9 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb, ...@@ -243,16 +240,9 @@ static int nfnetlink_rcv_msg(struct sk_buff *skb,
err = nfnetlink_check_attributes(ss, nlh, cda); err = nfnetlink_check_attributes(ss, nlh, cda);
if (err < 0) if (err < 0)
goto err_inval; return err;
return nc->call(nfnl, skb, nlh, cda);
err = nc->call(nfnl, skb, nlh, cda, errp);
*errp = err;
return err;
} }
err_inval:
*errp = -EINVAL;
return -1;
} }
static void nfnetlink_rcv(struct sock *sk, int len) static void nfnetlink_rcv(struct sock *sk, int len)
......
...@@ -759,7 +759,7 @@ static struct notifier_block nfulnl_rtnl_notifier = { ...@@ -759,7 +759,7 @@ static struct notifier_block nfulnl_rtnl_notifier = {
static int static int
nfulnl_recv_unsupp(struct sock *ctnl, struct sk_buff *skb, nfulnl_recv_unsupp(struct sock *ctnl, struct sk_buff *skb,
struct nlmsghdr *nlh, struct nfattr *nfqa[], int *errp) struct nlmsghdr *nlh, struct nfattr *nfqa[])
{ {
return -ENOTSUPP; return -ENOTSUPP;
} }
...@@ -797,7 +797,7 @@ static const int nfula_cfg_min[NFULA_CFG_MAX] = { ...@@ -797,7 +797,7 @@ static const int nfula_cfg_min[NFULA_CFG_MAX] = {
static int static int
nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb, nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
struct nlmsghdr *nlh, struct nfattr *nfula[], int *errp) struct nlmsghdr *nlh, struct nfattr *nfula[])
{ {
struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
u_int16_t group_num = ntohs(nfmsg->res_id); u_int16_t group_num = ntohs(nfmsg->res_id);
......
...@@ -783,7 +783,7 @@ static const int nfqa_verdict_min[NFQA_MAX] = { ...@@ -783,7 +783,7 @@ static const int nfqa_verdict_min[NFQA_MAX] = {
static int static int
nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb, nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb,
struct nlmsghdr *nlh, struct nfattr *nfqa[], int *errp) struct nlmsghdr *nlh, struct nfattr *nfqa[])
{ {
struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
u_int16_t queue_num = ntohs(nfmsg->res_id); u_int16_t queue_num = ntohs(nfmsg->res_id);
...@@ -848,7 +848,7 @@ nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb, ...@@ -848,7 +848,7 @@ nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb,
static int static int
nfqnl_recv_unsupp(struct sock *ctnl, struct sk_buff *skb, nfqnl_recv_unsupp(struct sock *ctnl, struct sk_buff *skb,
struct nlmsghdr *nlh, struct nfattr *nfqa[], int *errp) struct nlmsghdr *nlh, struct nfattr *nfqa[])
{ {
return -ENOTSUPP; return -ENOTSUPP;
} }
...@@ -865,7 +865,7 @@ static struct nf_queue_handler nfqh = { ...@@ -865,7 +865,7 @@ static struct nf_queue_handler nfqh = {
static int static int
nfqnl_recv_config(struct sock *ctnl, struct sk_buff *skb, nfqnl_recv_config(struct sock *ctnl, struct sk_buff *skb,
struct nlmsghdr *nlh, struct nfattr *nfqa[], int *errp) struct nlmsghdr *nlh, struct nfattr *nfqa[])
{ {
struct nfgenmsg *nfmsg = NLMSG_DATA(nlh); struct nfgenmsg *nfmsg = NLMSG_DATA(nlh);
u_int16_t queue_num = ntohs(nfmsg->res_id); u_int16_t queue_num = ntohs(nfmsg->res_id);
......
...@@ -1463,7 +1463,7 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err) ...@@ -1463,7 +1463,7 @@ void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err)
} }
static int netlink_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *, static int netlink_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *,
struct nlmsghdr *, int *)) struct nlmsghdr *))
{ {
struct nlmsghdr *nlh; struct nlmsghdr *nlh;
int err; int err;
...@@ -1483,13 +1483,11 @@ static int netlink_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *, ...@@ -1483,13 +1483,11 @@ static int netlink_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *,
if (nlh->nlmsg_type < NLMSG_MIN_TYPE) if (nlh->nlmsg_type < NLMSG_MIN_TYPE)
goto skip; goto skip;
if (cb(skb, nlh, &err) < 0) { err = cb(skb, nlh);
/* Not an error, but we have to interrupt processing if (err == -EINTR) {
* here. Note: that in this case we do not pull /* Not an error, but we interrupt processing */
* message from skb, it will be processed later. netlink_queue_skip(nlh, skb);
*/ return err;
if (err == 0)
return -1;
} }
skip: skip:
if (nlh->nlmsg_flags & NLM_F_ACK || err) if (nlh->nlmsg_flags & NLM_F_ACK || err)
...@@ -1515,9 +1513,14 @@ static int netlink_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *, ...@@ -1515,9 +1513,14 @@ static int netlink_rcv_skb(struct sk_buff *skb, int (*cb)(struct sk_buff *,
* *
* qlen must be initialized to 0 before the initial entry, afterwards * qlen must be initialized to 0 before the initial entry, afterwards
* the function may be called repeatedly until qlen reaches 0. * the function may be called repeatedly until qlen reaches 0.
*
* The callback function may return -EINTR to signal that processing
* of netlink messages shall be interrupted. In this case the message
* currently being processed will NOT be requeued onto the receive
* queue.
*/ */
void netlink_run_queue(struct sock *sk, unsigned int *qlen, void netlink_run_queue(struct sock *sk, unsigned int *qlen,
int (*cb)(struct sk_buff *, struct nlmsghdr *, int *)) int (*cb)(struct sk_buff *, struct nlmsghdr *))
{ {
struct sk_buff *skb; struct sk_buff *skb;
......
...@@ -295,60 +295,49 @@ int genl_unregister_family(struct genl_family *family) ...@@ -295,60 +295,49 @@ int genl_unregister_family(struct genl_family *family)
return -ENOENT; return -ENOENT;
} }
static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
int *errp)
{ {
struct genl_ops *ops; struct genl_ops *ops;
struct genl_family *family; struct genl_family *family;
struct genl_info info; struct genl_info info;
struct genlmsghdr *hdr = nlmsg_data(nlh); struct genlmsghdr *hdr = nlmsg_data(nlh);
int hdrlen, err = -EINVAL; int hdrlen, err;
family = genl_family_find_byid(nlh->nlmsg_type); family = genl_family_find_byid(nlh->nlmsg_type);
if (family == NULL) { if (family == NULL)
err = -ENOENT; return -ENOENT;
goto errout;
}
hdrlen = GENL_HDRLEN + family->hdrsize; hdrlen = GENL_HDRLEN + family->hdrsize;
if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen)) if (nlh->nlmsg_len < nlmsg_msg_size(hdrlen))
goto errout; return -EINVAL;
ops = genl_get_cmd(hdr->cmd, family); ops = genl_get_cmd(hdr->cmd, family);
if (ops == NULL) { if (ops == NULL)
err = -EOPNOTSUPP; return -EOPNOTSUPP;
goto errout;
}
if ((ops->flags & GENL_ADMIN_PERM) && security_netlink_recv(skb, CAP_NET_ADMIN)) { if ((ops->flags & GENL_ADMIN_PERM) &&
err = -EPERM; security_netlink_recv(skb, CAP_NET_ADMIN))
goto errout; return -EPERM;
}
if (nlh->nlmsg_flags & NLM_F_DUMP) { if (nlh->nlmsg_flags & NLM_F_DUMP) {
if (ops->dumpit == NULL) { if (ops->dumpit == NULL)
err = -EOPNOTSUPP; return -EOPNOTSUPP;
goto errout;
}
*errp = err = netlink_dump_start(genl_sock, skb, nlh, err = netlink_dump_start(genl_sock, skb, nlh,
ops->dumpit, ops->done); ops->dumpit, ops->done);
if (err == 0) if (err == 0)
skb_pull(skb, min(NLMSG_ALIGN(nlh->nlmsg_len), err = -EINTR;
skb->len)); return err;
return -1;
} }
if (ops->doit == NULL) { if (ops->doit == NULL)
err = -EOPNOTSUPP; return -EOPNOTSUPP;
goto errout;
}
if (family->attrbuf) { if (family->attrbuf) {
err = nlmsg_parse(nlh, hdrlen, family->attrbuf, family->maxattr, err = nlmsg_parse(nlh, hdrlen, family->attrbuf, family->maxattr,
ops->policy); ops->policy);
if (err < 0) if (err < 0)
goto errout; return err;
} }
info.snd_seq = nlh->nlmsg_seq; info.snd_seq = nlh->nlmsg_seq;
...@@ -358,12 +347,7 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, ...@@ -358,12 +347,7 @@ static int genl_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
info.userhdr = nlmsg_data(nlh) + GENL_HDRLEN; info.userhdr = nlmsg_data(nlh) + GENL_HDRLEN;
info.attrs = family->attrbuf; info.attrs = family->attrbuf;
*errp = err = ops->doit(skb, &info); return ops->doit(skb, &info);
return err;
errout:
*errp = err;
return -1;
} }
static void genl_rcv(struct sock *sk, int len) static void genl_rcv(struct sock *sk, int len)
......
...@@ -1852,46 +1852,39 @@ static struct xfrm_link { ...@@ -1852,46 +1852,39 @@ static struct xfrm_link {
[XFRM_MSG_MIGRATE - XFRM_MSG_BASE] = { .doit = xfrm_do_migrate }, [XFRM_MSG_MIGRATE - XFRM_MSG_BASE] = { .doit = xfrm_do_migrate },
}; };
static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *errp) static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
{ {
struct rtattr *xfrma[XFRMA_MAX]; struct rtattr *xfrma[XFRMA_MAX];
struct xfrm_link *link; struct xfrm_link *link;
int type, min_len; int type, min_len, err;
type = nlh->nlmsg_type; type = nlh->nlmsg_type;
/* Unknown message: reply with EINVAL */
if (type > XFRM_MSG_MAX) if (type > XFRM_MSG_MAX)
goto err_einval; return -EINVAL;
type -= XFRM_MSG_BASE; type -= XFRM_MSG_BASE;
link = &xfrm_dispatch[type]; link = &xfrm_dispatch[type];
/* All operations require privileges, even GET */ /* All operations require privileges, even GET */
if (security_netlink_recv(skb, CAP_NET_ADMIN)) { if (security_netlink_recv(skb, CAP_NET_ADMIN))
*errp = -EPERM; return -EPERM;
return -1;
}
if ((type == (XFRM_MSG_GETSA - XFRM_MSG_BASE) || if ((type == (XFRM_MSG_GETSA - XFRM_MSG_BASE) ||
type == (XFRM_MSG_GETPOLICY - XFRM_MSG_BASE)) && type == (XFRM_MSG_GETPOLICY - XFRM_MSG_BASE)) &&
(nlh->nlmsg_flags & NLM_F_DUMP)) { (nlh->nlmsg_flags & NLM_F_DUMP)) {
if (link->dump == NULL) if (link->dump == NULL)
goto err_einval; return -EINVAL;
if ((*errp = netlink_dump_start(xfrm_nl, skb, nlh,
link->dump, NULL)) != 0) {
return -1;
}
netlink_queue_skip(nlh, skb); err = netlink_dump_start(xfrm_nl, skb, nlh, link->dump, NULL);
return -1; if (err == 0)
err = -EINTR;
return err;
} }
memset(xfrma, 0, sizeof(xfrma)); memset(xfrma, 0, sizeof(xfrma));
if (nlh->nlmsg_len < (min_len = xfrm_msg_min[type])) if (nlh->nlmsg_len < (min_len = xfrm_msg_min[type]))
goto err_einval; return -EINVAL;
if (nlh->nlmsg_len > min_len) { if (nlh->nlmsg_len > min_len) {
int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len); int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
...@@ -1901,7 +1894,7 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *err ...@@ -1901,7 +1894,7 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *err
unsigned short flavor = attr->rta_type; unsigned short flavor = attr->rta_type;
if (flavor) { if (flavor) {
if (flavor > XFRMA_MAX) if (flavor > XFRMA_MAX)
goto err_einval; return -EINVAL;
xfrma[flavor - 1] = attr; xfrma[flavor - 1] = attr;
} }
attr = RTA_NEXT(attr, attrlen); attr = RTA_NEXT(attr, attrlen);
...@@ -1909,14 +1902,9 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *err ...@@ -1909,14 +1902,9 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh, int *err
} }
if (link->doit == NULL) if (link->doit == NULL)
goto err_einval; return -EINVAL;
*errp = link->doit(skb, nlh, xfrma);
return *errp;
err_einval: return link->doit(skb, nlh, xfrma);
*errp = -EINVAL;
return -1;
} }
static void xfrm_netlink_rcv(struct sock *sk, int len) static void xfrm_netlink_rcv(struct sock *sk, int len)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册