Skip to content

Commit 25c4cd2

Browse files
xemuldavem330
authored andcommitted
inet_diag: Switch the _dump to work with new header
Make inet_diag_dumo work with given header instead of calculating one from the nl message. The SOCK_DIAG_BY_FAMILY just passes skb's one through, the compat code converts the old header to new one. Also fix the bytecode calculation to find one at proper offset. Signed-off-by: Pavel Emelyanov <xemul@parallels.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fe50ce2 commit 25c4cd2

1 file changed

Lines changed: 53 additions & 18 deletions

File tree

‎net/ipv4/inet_diag.c‎

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,9 @@ static int inet_diag_bc_audit(const void *bytecode, int bytecode_len)
502502
static int inet_csk_diag_dump(struct sock *sk,
503503
struct sk_buff *skb,
504504
struct netlink_callback *cb,
505+
struct inet_diag_req *r,
505506
const struct nlattr *bc)
506507
{
507-
struct inet_diag_req_compat *r = NLMSG_DATA(cb->nlh);
508-
509508
if (bc != NULL) {
510509
struct inet_diag_entry entry;
511510
struct inet_sock *inet = inet_sk(sk);
@@ -539,10 +538,9 @@ static int inet_csk_diag_dump(struct sock *sk,
539538
static int inet_twsk_diag_dump(struct inet_timewait_sock *tw,
540539
struct sk_buff *skb,
541540
struct netlink_callback *cb,
541+
struct inet_diag_req *r,
542542
const struct nlattr *bc)
543543
{
544-
struct inet_diag_req_compat *r = NLMSG_DATA(cb->nlh);
545-
546544
if (bc != NULL) {
547545
struct inet_diag_entry entry;
548546

@@ -626,10 +624,10 @@ static int inet_diag_fill_req(struct sk_buff *skb, struct sock *sk,
626624

627625
static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
628626
struct netlink_callback *cb,
627+
struct inet_diag_req *r,
629628
const struct nlattr *bc)
630629
{
631630
struct inet_diag_entry entry;
632-
struct inet_diag_req_compat *r = NLMSG_DATA(cb->nlh);
633631
struct inet_connection_sock *icsk = inet_csk(sk);
634632
struct listen_sock *lopt;
635633
struct inet_sock *inet = inet_sk(sk);
@@ -708,19 +706,15 @@ static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
708706
return err;
709707
}
710708

711-
static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
709+
static int __inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
710+
struct inet_diag_req *r, struct nlattr *bc)
712711
{
713712
int i, num;
714713
int s_i, s_num;
715-
struct inet_diag_req_compat *r = NLMSG_DATA(cb->nlh);
716714
const struct inet_diag_handler *handler;
717715
struct inet_hashinfo *hashinfo;
718-
const struct nlattr *bc = NULL;
719716

720-
if (nlmsg_attrlen(cb->nlh, sizeof(struct inet_diag_req_compat)))
721-
bc = nlmsg_find_attr(cb->nlh, sizeof(*r), INET_DIAG_REQ_BYTECODE);
722-
723-
handler = inet_diag_lock_handler(inet_diag_type2proto(cb->nlh->nlmsg_type));
717+
handler = inet_diag_lock_handler(r->sdiag_protocol);
724718
if (IS_ERR(handler))
725719
goto unlock;
726720

@@ -758,7 +752,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
758752
cb->args[3] > 0)
759753
goto syn_recv;
760754

761-
if (inet_csk_diag_dump(sk, skb, cb, bc) < 0) {
755+
if (inet_csk_diag_dump(sk, skb, cb, r, bc) < 0) {
762756
spin_unlock_bh(&ilb->lock);
763757
goto done;
764758
}
@@ -767,7 +761,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
767761
if (!(r->idiag_states & TCPF_SYN_RECV))
768762
goto next_listen;
769763

770-
if (inet_diag_dump_reqs(skb, sk, cb, bc) < 0) {
764+
if (inet_diag_dump_reqs(skb, sk, cb, r, bc) < 0) {
771765
spin_unlock_bh(&ilb->lock);
772766
goto done;
773767
}
@@ -820,7 +814,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
820814
if (r->id.idiag_dport != inet->inet_dport &&
821815
r->id.idiag_dport)
822816
goto next_normal;
823-
if (inet_csk_diag_dump(sk, skb, cb, bc) < 0) {
817+
if (inet_csk_diag_dump(sk, skb, cb, r, bc) < 0) {
824818
spin_unlock_bh(lock);
825819
goto done;
826820
}
@@ -842,7 +836,7 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
842836
if (r->id.idiag_dport != tw->tw_dport &&
843837
r->id.idiag_dport)
844838
goto next_dying;
845-
if (inet_twsk_diag_dump(tw, skb, cb, bc) < 0) {
839+
if (inet_twsk_diag_dump(tw, skb, cb, r, bc) < 0) {
846840
spin_unlock_bh(lock);
847841
goto done;
848842
}
@@ -861,6 +855,36 @@ static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
861855
return skb->len;
862856
}
863857

858+
static int inet_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
859+
{
860+
struct nlattr *bc = NULL;
861+
int hdrlen = sizeof(struct inet_diag_req);
862+
863+
if (nlmsg_attrlen(cb->nlh, hdrlen))
864+
bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE);
865+
866+
return __inet_diag_dump(skb, cb, (struct inet_diag_req *)NLMSG_DATA(cb->nlh), bc);
867+
}
868+
869+
static int inet_diag_dump_compat(struct sk_buff *skb, struct netlink_callback *cb)
870+
{
871+
struct inet_diag_req_compat *rc = NLMSG_DATA(cb->nlh);
872+
struct inet_diag_req req;
873+
struct nlattr *bc = NULL;
874+
int hdrlen = sizeof(struct inet_diag_req_compat);
875+
876+
req.sdiag_family = rc->idiag_family;
877+
req.sdiag_protocol = inet_diag_type2proto(cb->nlh->nlmsg_type);
878+
req.idiag_ext = rc->idiag_ext;
879+
req.idiag_states = rc->idiag_states;
880+
req.id = rc->id;
881+
882+
if (nlmsg_attrlen(cb->nlh, hdrlen))
883+
bc = nlmsg_find_attr(cb->nlh, hdrlen, INET_DIAG_REQ_BYTECODE);
884+
885+
return __inet_diag_dump(skb, cb, &req, bc);
886+
}
887+
864888
static int inet_diag_get_exact_compat(struct sk_buff *in_skb,
865889
const struct nlmsghdr *nlh)
866890
{
@@ -897,7 +921,7 @@ static int inet_diag_rcv_msg_compat(struct sk_buff *skb, struct nlmsghdr *nlh)
897921
}
898922

899923
return netlink_dump_start(sdiagnl, skb, nlh,
900-
inet_diag_dump, NULL, 0);
924+
inet_diag_dump_compat, NULL, 0);
901925
}
902926

903927
return inet_diag_get_exact_compat(skb, nlh);
@@ -911,7 +935,18 @@ static int inet_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
911935
return -EINVAL;
912936

913937
if (h->nlmsg_flags & NLM_F_DUMP) {
914-
return -EAFNOSUPPORT;
938+
if (nlmsg_attrlen(h, hdrlen)) {
939+
struct nlattr *attr;
940+
attr = nlmsg_find_attr(h, hdrlen,
941+
INET_DIAG_REQ_BYTECODE);
942+
if (attr == NULL ||
943+
nla_len(attr) < sizeof(struct inet_diag_bc_op) ||
944+
inet_diag_bc_audit(nla_data(attr), nla_len(attr)))
945+
return -EINVAL;
946+
}
947+
948+
return netlink_dump_start(sdiagnl, skb, h,
949+
inet_diag_dump, NULL, 0);
915950
}
916951

917952
return inet_diag_get_exact(skb, h, (struct inet_diag_req *)NLMSG_DATA(h));

0 commit comments

Comments
 (0)