Skip to content

Commit 5f3eea6

Browse files
0x7f454c46klassert
authored andcommitted
xfrm/compat: Attach xfrm dumps to 64=>32 bit translator
Currently nlmsg_unicast() is used by functions that dump structures that can be different in size for compat tasks, see dump_one_state() and dump_one_policy(). The following nlmsg_unicast() users exist today in xfrm: Function | Message can be different | in size on compat -------------------------------------------|------------------------------ xfrm_get_spdinfo() | N xfrm_get_sadinfo() | N xfrm_get_sa() | Y xfrm_alloc_userspi() | Y xfrm_get_policy() | Y xfrm_get_ae() | N Besides, dump_one_state() and dump_one_policy() can be used by filtered netlink dump for XFRM_MSG_GETSA, XFRM_MSG_GETPOLICY. Just as for xfrm multicast, allocate frag_list for compat skb journey down to recvmsg() which will give user the desired skb according to syscall bitness. Signed-off-by: Dmitry Safonov <dima@arista.com> Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
1 parent 5461fc0 commit 5f3eea6

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

‎net/xfrm/xfrm_user.c‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -975,6 +975,7 @@ static int dump_one_state(struct xfrm_state *x, int count, void *ptr)
975975
struct xfrm_dump_info *sp = ptr;
976976
struct sk_buff *in_skb = sp->in_skb;
977977
struct sk_buff *skb = sp->out_skb;
978+
struct xfrm_translator *xtr;
978979
struct xfrm_usersa_info *p;
979980
struct nlmsghdr *nlh;
980981
int err;
@@ -992,6 +993,18 @@ static int dump_one_state(struct xfrm_state *x, int count, void *ptr)
992993
return err;
993994
}
994995
nlmsg_end(skb, nlh);
996+
997+
xtr = xfrm_get_translator();
998+
if (xtr) {
999+
err = xtr->alloc_compat(skb, nlh);
1000+
1001+
xfrm_put_translator(xtr);
1002+
if (err) {
1003+
nlmsg_cancel(skb, nlh);
1004+
return err;
1005+
}
1006+
}
1007+
9951008
return 0;
9961009
}
9971010

@@ -1320,6 +1333,7 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
13201333
struct net *net = sock_net(skb->sk);
13211334
struct xfrm_state *x;
13221335
struct xfrm_userspi_info *p;
1336+
struct xfrm_translator *xtr;
13231337
struct sk_buff *resp_skb;
13241338
xfrm_address_t *daddr;
13251339
int family;
@@ -1370,6 +1384,17 @@ static int xfrm_alloc_userspi(struct sk_buff *skb, struct nlmsghdr *nlh,
13701384
goto out;
13711385
}
13721386

1387+
xtr = xfrm_get_translator();
1388+
if (xtr) {
1389+
err = xtr->alloc_compat(skb, nlmsg_hdr(skb));
1390+
1391+
xfrm_put_translator(xtr);
1392+
if (err) {
1393+
kfree_skb(resp_skb);
1394+
goto out;
1395+
}
1396+
}
1397+
13731398
err = nlmsg_unicast(net->xfrm.nlsk, resp_skb, NETLINK_CB(skb).portid);
13741399

13751400
out:
@@ -1776,6 +1801,7 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr
17761801
struct xfrm_userpolicy_info *p;
17771802
struct sk_buff *in_skb = sp->in_skb;
17781803
struct sk_buff *skb = sp->out_skb;
1804+
struct xfrm_translator *xtr;
17791805
struct nlmsghdr *nlh;
17801806
int err;
17811807

@@ -1800,6 +1826,18 @@ static int dump_one_policy(struct xfrm_policy *xp, int dir, int count, void *ptr
18001826
return err;
18011827
}
18021828
nlmsg_end(skb, nlh);
1829+
1830+
xtr = xfrm_get_translator();
1831+
if (xtr) {
1832+
err = xtr->alloc_compat(skb, nlh);
1833+
1834+
xfrm_put_translator(xtr);
1835+
if (err) {
1836+
nlmsg_cancel(skb, nlh);
1837+
return err;
1838+
}
1839+
}
1840+
18031841
return 0;
18041842
}
18051843

0 commit comments

Comments
 (0)