Message ID | 1471975571-26612-1-git-send-email-lorenzo@google.com |
---|---|
State | Changes Requested, archived |
Delegated to: | David Miller |
Headers | show |
On Wed, 2016-08-24 at 03:06 +0900, Lorenzo Colitti wrote: > 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: Lorenzo Colitti <lorenzo@google.com> > --- > net/ipv4/inet_diag.c | 35 ++++++++++++++++++++++++----------- > 1 file changed, 24 insertions(+), 11 deletions(-) > > diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c > index 38c2c47..a835f94 100644 > --- a/net/ipv4/inet_diag.c > +++ b/net/ipv4/inet_diag.c > @@ -706,10 +706,23 @@ static bool valid_port_comparison(const struct inet_diag_bc_op *op, > return true; > } > > -static int inet_diag_bc_audit(const void *bytecode, int bytecode_len) > +static bool valid_markcond(const struct inet_diag_bc_op *op, int len, > + int *min_len) > { > - const void *bc = bytecode; > - int len = bytecode_len; > + *min_len += sizeof(struct inet_diag_markcond); > + return len >= *min_len; > +} I do not see how this can compile, since you introduce "struct inet_diag_markcond" in the following patch ?
Hi Lorenzo, [auto build test ERROR on net-next/master] url: https://github.com/0day-ci/linux/commits/Lorenzo-Colitti/net-diag-slightly-refactor-the-inet_diag_bc_audit-error-checks/20160824-020848 config: x86_64-randconfig-x015-201634 (attached as .config) compiler: gcc-6 (Debian 6.1.1-9) 6.1.1 20160705 reproduce: # save the attached .config to linux build tree make ARCH=x86_64 Note: the linux-review/Lorenzo-Colitti/net-diag-slightly-refactor-the-inet_diag_bc_audit-error-checks/20160824-020848 HEAD a2280f98a90602586a70251ad6f794ebe70f687a builds fine. It only hurts bisectibility. All errors (new ones prefixed by >>): net/ipv4/inet_diag.c: In function 'valid_markcond': >> net/ipv4/inet_diag.c:712:21: error: invalid application of 'sizeof' to incomplete type 'struct inet_diag_markcond' *min_len += sizeof(struct inet_diag_markcond); ^~~~~~ At top level: net/ipv4/inet_diag.c:709:13: warning: 'valid_markcond' defined but not used [-Wunused-function] static bool valid_markcond(const struct inet_diag_bc_op *op, int len, ^~~~~~~~~~~~~~ vim +712 net/ipv4/inet_diag.c 706 return true; 707 } 708 709 static bool valid_markcond(const struct inet_diag_bc_op *op, int len, 710 int *min_len) 711 { > 712 *min_len += sizeof(struct inet_diag_markcond); 713 return len >= *min_len; 714 } 715 --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c index 38c2c47..a835f94 100644 --- a/net/ipv4/inet_diag.c +++ b/net/ipv4/inet_diag.c @@ -706,10 +706,23 @@ static bool valid_port_comparison(const struct inet_diag_bc_op *op, return true; } -static int inet_diag_bc_audit(const void *bytecode, int bytecode_len) +static bool valid_markcond(const struct inet_diag_bc_op *op, int len, + int *min_len) { - const void *bc = bytecode; - int len = bytecode_len; + *min_len += sizeof(struct inet_diag_markcond); + return len >= *min_len; +} + +static int inet_diag_bc_audit(struct nlattr *attr) +{ + const void *bytecode, *bc; + 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) { int min_len = sizeof(struct inet_diag_bc_op); @@ -1020,13 +1033,13 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh) if (nlh->nlmsg_flags & NLM_F_DUMP) { if (nlmsg_attrlen(nlh, hdrlen)) { struct nlattr *attr; + int err; attr = nlmsg_find_attr(nlh, hdrlen, INET_DIAG_REQ_BYTECODE); - if (!attr || - nla_len(attr) < sizeof(struct inet_diag_bc_op) || - inet_diag_bc_audit(nla_data(attr), nla_len(attr))) - return -EINVAL; + err = inet_diag_bc_audit(attr); + if (err) + return err; } { struct netlink_dump_control c = { @@ -1051,13 +1064,13 @@ static int inet_diag_handler_cmd(struct sk_buff *skb, struct nlmsghdr *h) h->nlmsg_flags & NLM_F_DUMP) { if (nlmsg_attrlen(h, hdrlen)) { struct nlattr *attr; + int err; attr = nlmsg_find_attr(h, hdrlen, INET_DIAG_REQ_BYTECODE); - if (!attr || - nla_len(attr) < sizeof(struct inet_diag_bc_op) || - inet_diag_bc_audit(nla_data(attr), nla_len(attr))) - return -EINVAL; + err = inet_diag_bc_audit(attr); + if (err) + return err; } { struct netlink_dump_control c = {
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: Lorenzo Colitti <lorenzo@google.com> --- net/ipv4/inet_diag.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-)