Skip to content

Commit a7bd9a4

Browse files
tgrafDavid S. Miller
authored andcommitted
[XFRM] netlink: Use nlmsg_parse() to parse attributes
Uses nlmsg_parse() to parse the attributes. This actually changes behaviour as unknown attributes (type > MAXTYPE) no longer cause an error. Instead unknown attributes will be ignored henceforth to keep older kernels compatible with more recent userspace tools. Signed-off-by: Thomas Graf <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 7deb226 commit a7bd9a4

File tree

1 file changed

+12
-26
lines changed

1 file changed

+12
-26
lines changed

net/xfrm/xfrm_user.c

Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ static int xfrm_send_migrate(struct xfrm_selector *sel, u8 dir, u8 type,
18901890
}
18911891
#endif
18921892

1893-
#define XMSGSIZE(type) NLMSG_LENGTH(sizeof(struct type))
1893+
#define XMSGSIZE(type) sizeof(struct type)
18941894

18951895
static const int xfrm_msg_min[XFRM_NR_MSGTYPES] = {
18961896
[XFRM_MSG_NEWSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_info),
@@ -1906,13 +1906,13 @@ static const int xfrm_msg_min[XFRM_NR_MSGTYPES] = {
19061906
[XFRM_MSG_UPDSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_info),
19071907
[XFRM_MSG_POLEXPIRE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_polexpire),
19081908
[XFRM_MSG_FLUSHSA - XFRM_MSG_BASE] = XMSGSIZE(xfrm_usersa_flush),
1909-
[XFRM_MSG_FLUSHPOLICY - XFRM_MSG_BASE] = NLMSG_LENGTH(0),
1909+
[XFRM_MSG_FLUSHPOLICY - XFRM_MSG_BASE] = 0,
19101910
[XFRM_MSG_NEWAE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_aevent_id),
19111911
[XFRM_MSG_GETAE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_aevent_id),
19121912
[XFRM_MSG_REPORT - XFRM_MSG_BASE] = XMSGSIZE(xfrm_user_report),
19131913
[XFRM_MSG_MIGRATE - XFRM_MSG_BASE] = XMSGSIZE(xfrm_userpolicy_id),
1914-
[XFRM_MSG_GETSADINFO - XFRM_MSG_BASE] = NLMSG_LENGTH(sizeof(u32)),
1915-
[XFRM_MSG_GETSPDINFO - XFRM_MSG_BASE] = NLMSG_LENGTH(sizeof(u32)),
1914+
[XFRM_MSG_GETSADINFO - XFRM_MSG_BASE] = sizeof(u32),
1915+
[XFRM_MSG_GETSPDINFO - XFRM_MSG_BASE] = sizeof(u32),
19161916
};
19171917

19181918
#undef XMSGSIZE
@@ -1946,9 +1946,9 @@ static struct xfrm_link {
19461946

19471947
static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
19481948
{
1949-
struct rtattr *xfrma[XFRMA_MAX];
1949+
struct nlattr *xfrma[XFRMA_MAX+1];
19501950
struct xfrm_link *link;
1951-
int type, min_len;
1951+
int type, err;
19521952

19531953
type = nlh->nlmsg_type;
19541954
if (type > XFRM_MSG_MAX)
@@ -1970,30 +1970,16 @@ static int xfrm_user_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
19701970
return netlink_dump_start(xfrm_nl, skb, nlh, link->dump, NULL);
19711971
}
19721972

1973-
memset(xfrma, 0, sizeof(xfrma));
1974-
1975-
if (nlh->nlmsg_len < (min_len = xfrm_msg_min[type]))
1976-
return -EINVAL;
1977-
1978-
if (nlh->nlmsg_len > min_len) {
1979-
int attrlen = nlh->nlmsg_len - NLMSG_ALIGN(min_len);
1980-
struct rtattr *attr = (void *) nlh + NLMSG_ALIGN(min_len);
1981-
1982-
while (RTA_OK(attr, attrlen)) {
1983-
unsigned short flavor = attr->rta_type;
1984-
if (flavor) {
1985-
if (flavor > XFRMA_MAX)
1986-
return -EINVAL;
1987-
xfrma[flavor - 1] = attr;
1988-
}
1989-
attr = RTA_NEXT(attr, attrlen);
1990-
}
1991-
}
1973+
/* FIXME: Temporary hack, nlmsg_parse() starts at xfrma[1], old code
1974+
* expects first attribute at xfrma[0] */
1975+
err = nlmsg_parse(nlh, xfrm_msg_min[type], xfrma-1, XFRMA_MAX, NULL);
1976+
if (err < 0)
1977+
return err;
19921978

19931979
if (link->doit == NULL)
19941980
return -EINVAL;
19951981

1996-
return link->doit(skb, nlh, xfrma);
1982+
return link->doit(skb, nlh, (struct rtattr **) xfrma);
19971983
}
19981984

19991985
static void xfrm_netlink_rcv(struct sock *sk, int len)

0 commit comments

Comments
 (0)