* [PATCH 1/2] netlink: Make nlmsg_find_attr take a const nlmsghdr*.
@ 2010-11-04 2:35 Nelson Elhage
2010-11-04 2:35 ` [PATCH 2/2] inet_diag: Make sure we actually run the same bytecode we audited Nelson Elhage
2010-11-04 19:26 ` [PATCH 1/2] netlink: Make nlmsg_find_attr take a const nlmsghdr* David Miller
0 siblings, 2 replies; 5+ messages in thread
From: Nelson Elhage @ 2010-11-04 2:35 UTC (permalink / raw)
To: netdev; +Cc: Nelson Elhage
This will let us use it on a nlmsghdr stored inside a netlink_callback.
Signed-off-by: Nelson Elhage <nelhage@ksplice.com>
---
include/net/netlink.h | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/include/net/netlink.h b/include/net/netlink.h
index f3b201d..9801c55 100644
--- a/include/net/netlink.h
+++ b/include/net/netlink.h
@@ -384,7 +384,7 @@ static inline int nlmsg_parse(const struct nlmsghdr *nlh, int hdrlen,
*
* Returns the first attribute which matches the specified type.
*/
-static inline struct nlattr *nlmsg_find_attr(struct nlmsghdr *nlh,
+static inline struct nlattr *nlmsg_find_attr(const struct nlmsghdr *nlh,
int hdrlen, int attrtype)
{
return nla_find(nlmsg_attrdata(nlh, hdrlen),
--
1.7.1.31.g6297e
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] inet_diag: Make sure we actually run the same bytecode we audited.
2010-11-04 2:35 [PATCH 1/2] netlink: Make nlmsg_find_attr take a const nlmsghdr* Nelson Elhage
@ 2010-11-04 2:35 ` Nelson Elhage
2010-11-04 13:28 ` Thomas Graf
2010-11-04 19:26 ` [PATCH 1/2] netlink: Make nlmsg_find_attr take a const nlmsghdr* David Miller
1 sibling, 1 reply; 5+ messages in thread
From: Nelson Elhage @ 2010-11-04 2:35 UTC (permalink / raw)
To: netdev; +Cc: Nelson Elhage
We were using nlmsg_find_attr() to look up the bytecode by attribute when
auditing, but then just using the first attribute when actually running
bytecode. So, if we received a message with two attribute elements, where only
the second had type INET_DIAG_REQ_BYTECODE, we would validate and run different
bytecode strings.
Fix this by consistently using nlmsg_find_attr everywhere.
Signed-off-by: Nelson Elhage <nelhage@ksplice.com>
---
net/ipv4/inet_diag.c | 27 ++++++++++++++++-----------
1 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/net/ipv4/inet_diag.c b/net/ipv4/inet_diag.c
index ba80426..2ada171 100644
--- a/net/ipv4/inet_diag.c
+++ b/net/ipv4/inet_diag.c
@@ -490,9 +490,11 @@ static int inet_csk_diag_dump(struct sock *sk,
{
struct inet_diag_req *r = NLMSG_DATA(cb->nlh);
- if (cb->nlh->nlmsg_len > 4 + NLMSG_SPACE(sizeof(*r))) {
+ if (nlmsg_attrlen(cb->nlh, sizeof(*r))) {
struct inet_diag_entry entry;
- struct rtattr *bc = (struct rtattr *)(r + 1);
+ const struct nlattr *bc = nlmsg_find_attr(cb->nlh,
+ sizeof(*r),
+ INET_DIAG_REQ_BYTECODE);
struct inet_sock *inet = inet_sk(sk);
entry.family = sk->sk_family;
@@ -512,7 +514,7 @@ static int inet_csk_diag_dump(struct sock *sk,
entry.dport = ntohs(inet->inet_dport);
entry.userlocks = sk->sk_userlocks;
- if (!inet_diag_bc_run(RTA_DATA(bc), RTA_PAYLOAD(bc), &entry))
+ if (!inet_diag_bc_run(nla_data(bc), nla_len(bc), &entry))
return 0;
}
@@ -527,9 +529,11 @@ static int inet_twsk_diag_dump(struct inet_timewait_sock *tw,
{
struct inet_diag_req *r = NLMSG_DATA(cb->nlh);
- if (cb->nlh->nlmsg_len > 4 + NLMSG_SPACE(sizeof(*r))) {
+ if (nlmsg_attrlen(cb->nlh, sizeof(*r))) {
struct inet_diag_entry entry;
- struct rtattr *bc = (struct rtattr *)(r + 1);
+ const struct nlattr *bc = nlmsg_find_attr(cb->nlh,
+ sizeof(*r),
+ INET_DIAG_REQ_BYTECODE);
entry.family = tw->tw_family;
#if defined(CONFIG_IPV6) || defined (CONFIG_IPV6_MODULE)
@@ -548,7 +552,7 @@ static int inet_twsk_diag_dump(struct inet_timewait_sock *tw,
entry.dport = ntohs(tw->tw_dport);
entry.userlocks = 0;
- if (!inet_diag_bc_run(RTA_DATA(bc), RTA_PAYLOAD(bc), &entry))
+ if (!inet_diag_bc_run(nla_data(bc), nla_len(bc), &entry))
return 0;
}
@@ -618,7 +622,7 @@ static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
struct inet_diag_req *r = NLMSG_DATA(cb->nlh);
struct inet_connection_sock *icsk = inet_csk(sk);
struct listen_sock *lopt;
- struct rtattr *bc = NULL;
+ const struct nlattr *bc = NULL;
struct inet_sock *inet = inet_sk(sk);
int j, s_j;
int reqnum, s_reqnum;
@@ -638,8 +642,9 @@ static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
if (!lopt || !lopt->qlen)
goto out;
- if (cb->nlh->nlmsg_len > 4 + NLMSG_SPACE(sizeof(*r))) {
- bc = (struct rtattr *)(r + 1);
+ if (nlmsg_attrlen(cb->nlh, sizeof(*r))) {
+ bc = nlmsg_find_attr(cb->nlh, sizeof(*r),
+ INET_DIAG_REQ_BYTECODE);
entry.sport = inet->inet_num;
entry.userlocks = sk->sk_userlocks;
}
@@ -672,8 +677,8 @@ static int inet_diag_dump_reqs(struct sk_buff *skb, struct sock *sk,
&ireq->rmt_addr;
entry.dport = ntohs(ireq->rmt_port);
- if (!inet_diag_bc_run(RTA_DATA(bc),
- RTA_PAYLOAD(bc), &entry))
+ if (!inet_diag_bc_run(nla_data(bc),
+ nla_len(bc), &entry))
continue;
}
--
1.7.1.31.g6297e
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] inet_diag: Make sure we actually run the same bytecode we audited.
2010-11-04 2:35 ` [PATCH 2/2] inet_diag: Make sure we actually run the same bytecode we audited Nelson Elhage
@ 2010-11-04 13:28 ` Thomas Graf
2010-11-04 19:26 ` David Miller
0 siblings, 1 reply; 5+ messages in thread
From: Thomas Graf @ 2010-11-04 13:28 UTC (permalink / raw)
To: Nelson Elhage; +Cc: netdev
On Wed, Nov 03, 2010 at 10:35:41PM -0400, Nelson Elhage wrote:
> We were using nlmsg_find_attr() to look up the bytecode by attribute when
> auditing, but then just using the first attribute when actually running
> bytecode. So, if we received a message with two attribute elements, where only
> the second had type INET_DIAG_REQ_BYTECODE, we would validate and run different
> bytecode strings.
>
> Fix this by consistently using nlmsg_find_attr everywhere.
>
> Signed-off-by: Nelson Elhage <nelhage@ksplice.com>
Both patches look good.
Signed-off-by: Thomas Graf <tgraf@infradead.org>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] netlink: Make nlmsg_find_attr take a const nlmsghdr*.
2010-11-04 2:35 [PATCH 1/2] netlink: Make nlmsg_find_attr take a const nlmsghdr* Nelson Elhage
2010-11-04 2:35 ` [PATCH 2/2] inet_diag: Make sure we actually run the same bytecode we audited Nelson Elhage
@ 2010-11-04 19:26 ` David Miller
1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2010-11-04 19:26 UTC (permalink / raw)
To: nelhage; +Cc: netdev
From: Nelson Elhage <nelhage@ksplice.com>
Date: Wed, 3 Nov 2010 22:35:40 -0400
> This will let us use it on a nlmsghdr stored inside a netlink_callback.
>
> Signed-off-by: Nelson Elhage <nelhage@ksplice.com>
Applied.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] inet_diag: Make sure we actually run the same bytecode we audited.
2010-11-04 13:28 ` Thomas Graf
@ 2010-11-04 19:26 ` David Miller
0 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2010-11-04 19:26 UTC (permalink / raw)
To: tgraf; +Cc: nelhage, netdev
From: Thomas Graf <tgraf@infradead.org>
Date: Thu, 4 Nov 2010 09:28:02 -0400
> On Wed, Nov 03, 2010 at 10:35:41PM -0400, Nelson Elhage wrote:
>> We were using nlmsg_find_attr() to look up the bytecode by attribute when
>> auditing, but then just using the first attribute when actually running
>> bytecode. So, if we received a message with two attribute elements, where only
>> the second had type INET_DIAG_REQ_BYTECODE, we would validate and run different
>> bytecode strings.
>>
>> Fix this by consistently using nlmsg_find_attr everywhere.
>>
>> Signed-off-by: Nelson Elhage <nelhage@ksplice.com>
>
> Both patches look good.
>
> Signed-off-by: Thomas Graf <tgraf@infradead.org>
Applied.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-11-04 19:26 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-04 2:35 [PATCH 1/2] netlink: Make nlmsg_find_attr take a const nlmsghdr* Nelson Elhage
2010-11-04 2:35 ` [PATCH 2/2] inet_diag: Make sure we actually run the same bytecode we audited Nelson Elhage
2010-11-04 13:28 ` Thomas Graf
2010-11-04 19:26 ` David Miller
2010-11-04 19:26 ` [PATCH 1/2] netlink: Make nlmsg_find_attr take a const nlmsghdr* David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).