* [PATCH 0/4] connector fixes
@ 2013-09-30 20:03 Mathias Krause
2013-09-30 20:03 ` [PATCH 1/4] proc connector: fix info leaks Mathias Krause
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Mathias Krause @ 2013-09-30 20:03 UTC (permalink / raw)
To: Evgeniy Polyakov; +Cc: Mathias Krause, netdev
This series fixes a few netlink related issues of the connector interface.
The first two patches are bug fixes. The last two are cleanups.
Please apply!
Mathias Krause (4):
proc connector: fix info leaks
connector: use nlmsg_len() to check message length
connector: use 'size' everywhere in cn_netlink_send()
connector - documentation: simplify netlink message length assignment
Documentation/connector/ucon.c | 2 +-
drivers/connector/cn_proc.c | 18 ++++++++++++++++++
drivers/connector/connector.c | 9 +++++----
3 files changed, 24 insertions(+), 5 deletions(-)
--
1.7.10.4
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 1/4] proc connector: fix info leaks 2013-09-30 20:03 [PATCH 0/4] connector fixes Mathias Krause @ 2013-09-30 20:03 ` Mathias Krause 2013-09-30 20:03 ` [PATCH 2/4] connector: use nlmsg_len() to check message length Mathias Krause ` (3 subsequent siblings) 4 siblings, 0 replies; 7+ messages in thread From: Mathias Krause @ 2013-09-30 20:03 UTC (permalink / raw) To: Evgeniy Polyakov; +Cc: Mathias Krause, netdev Initialize event_data for all possible message types to prevent leaking kernel stack contents to userland (up to 20 bytes). Also set the flags member of the connector message to 0 to prevent leaking two more stack bytes this way. Cc: stable@vger.kernel.org # v2.6.15+ Signed-off-by: Mathias Krause <minipli@googlemail.com> --- drivers/connector/cn_proc.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c index 08ae128..c73fc2b 100644 --- a/drivers/connector/cn_proc.c +++ b/drivers/connector/cn_proc.c @@ -65,6 +65,7 @@ void proc_fork_connector(struct task_struct *task) msg = (struct cn_msg *)buffer; ev = (struct proc_event *)msg->data; + memset(&ev->event_data, 0, sizeof(ev->event_data)); get_seq(&msg->seq, &ev->cpu); ktime_get_ts(&ts); /* get high res monotonic timestamp */ put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); @@ -80,6 +81,7 @@ void proc_fork_connector(struct task_struct *task) memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = 0; /* not used */ msg->len = sizeof(*ev); + msg->flags = 0; /* not used */ /* If cn_netlink_send() failed, the data is not sent */ cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); } @@ -96,6 +98,7 @@ void proc_exec_connector(struct task_struct *task) msg = (struct cn_msg *)buffer; ev = (struct proc_event *)msg->data; + memset(&ev->event_data, 0, sizeof(ev->event_data)); get_seq(&msg->seq, &ev->cpu); ktime_get_ts(&ts); /* get high res monotonic timestamp */ put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); @@ -106,6 +109,7 @@ void proc_exec_connector(struct task_struct *task) memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = 0; /* not used */ msg->len = sizeof(*ev); + msg->flags = 0; /* not used */ cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); } @@ -122,6 +126,7 @@ void proc_id_connector(struct task_struct *task, int which_id) msg = (struct cn_msg *)buffer; ev = (struct proc_event *)msg->data; + memset(&ev->event_data, 0, sizeof(ev->event_data)); ev->what = which_id; ev->event_data.id.process_pid = task->pid; ev->event_data.id.process_tgid = task->tgid; @@ -145,6 +150,7 @@ void proc_id_connector(struct task_struct *task, int which_id) memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = 0; /* not used */ msg->len = sizeof(*ev); + msg->flags = 0; /* not used */ cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); } @@ -160,6 +166,7 @@ void proc_sid_connector(struct task_struct *task) msg = (struct cn_msg *)buffer; ev = (struct proc_event *)msg->data; + memset(&ev->event_data, 0, sizeof(ev->event_data)); get_seq(&msg->seq, &ev->cpu); ktime_get_ts(&ts); /* get high res monotonic timestamp */ put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); @@ -170,6 +177,7 @@ void proc_sid_connector(struct task_struct *task) memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = 0; /* not used */ msg->len = sizeof(*ev); + msg->flags = 0; /* not used */ cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); } @@ -185,6 +193,7 @@ void proc_ptrace_connector(struct task_struct *task, int ptrace_id) msg = (struct cn_msg *)buffer; ev = (struct proc_event *)msg->data; + memset(&ev->event_data, 0, sizeof(ev->event_data)); get_seq(&msg->seq, &ev->cpu); ktime_get_ts(&ts); /* get high res monotonic timestamp */ put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); @@ -203,6 +212,7 @@ void proc_ptrace_connector(struct task_struct *task, int ptrace_id) memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = 0; /* not used */ msg->len = sizeof(*ev); + msg->flags = 0; /* not used */ cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); } @@ -218,6 +228,7 @@ void proc_comm_connector(struct task_struct *task) msg = (struct cn_msg *)buffer; ev = (struct proc_event *)msg->data; + memset(&ev->event_data, 0, sizeof(ev->event_data)); get_seq(&msg->seq, &ev->cpu); ktime_get_ts(&ts); /* get high res monotonic timestamp */ put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); @@ -229,6 +240,7 @@ void proc_comm_connector(struct task_struct *task) memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = 0; /* not used */ msg->len = sizeof(*ev); + msg->flags = 0; /* not used */ cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); } @@ -244,6 +256,7 @@ void proc_coredump_connector(struct task_struct *task) msg = (struct cn_msg *)buffer; ev = (struct proc_event *)msg->data; + memset(&ev->event_data, 0, sizeof(ev->event_data)); get_seq(&msg->seq, &ev->cpu); ktime_get_ts(&ts); /* get high res monotonic timestamp */ put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); @@ -254,6 +267,7 @@ void proc_coredump_connector(struct task_struct *task) memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = 0; /* not used */ msg->len = sizeof(*ev); + msg->flags = 0; /* not used */ cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); } @@ -269,6 +283,7 @@ void proc_exit_connector(struct task_struct *task) msg = (struct cn_msg *)buffer; ev = (struct proc_event *)msg->data; + memset(&ev->event_data, 0, sizeof(ev->event_data)); get_seq(&msg->seq, &ev->cpu); ktime_get_ts(&ts); /* get high res monotonic timestamp */ put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); @@ -281,6 +296,7 @@ void proc_exit_connector(struct task_struct *task) memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = 0; /* not used */ msg->len = sizeof(*ev); + msg->flags = 0; /* not used */ cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); } @@ -304,6 +320,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack) msg = (struct cn_msg *)buffer; ev = (struct proc_event *)msg->data; + memset(&ev->event_data, 0, sizeof(ev->event_data)); msg->seq = rcvd_seq; ktime_get_ts(&ts); /* get high res monotonic timestamp */ put_unaligned(timespec_to_ns(&ts), (__u64 *)&ev->timestamp_ns); @@ -313,6 +330,7 @@ static void cn_proc_ack(int err, int rcvd_seq, int rcvd_ack) memcpy(&msg->id, &cn_proc_event_id, sizeof(msg->id)); msg->ack = rcvd_ack + 1; msg->len = sizeof(*ev); + msg->flags = 0; /* not used */ cn_netlink_send(msg, CN_IDX_PROC, GFP_KERNEL); } -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/4] connector: use nlmsg_len() to check message length 2013-09-30 20:03 [PATCH 0/4] connector fixes Mathias Krause 2013-09-30 20:03 ` [PATCH 1/4] proc connector: fix info leaks Mathias Krause @ 2013-09-30 20:03 ` Mathias Krause 2013-09-30 20:03 ` [PATCH 3/4] connector: use 'size' everywhere in cn_netlink_send() Mathias Krause ` (2 subsequent siblings) 4 siblings, 0 replies; 7+ messages in thread From: Mathias Krause @ 2013-09-30 20:03 UTC (permalink / raw) To: Evgeniy Polyakov; +Cc: Mathias Krause, netdev The current code tests the length of the whole netlink message to be at least as long to fit a cn_msg. This is wrong as nlmsg_len includes the length of the netlink message header. Use nlmsg_len() instead to fix this "off-by-NLMSG_HDRLEN" size check. Cc: stable@vger.kernel.org # v2.6.14+ Signed-off-by: Mathias Krause <minipli@googlemail.com> --- drivers/connector/connector.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c index 6ecfa75..0daa11e 100644 --- a/drivers/connector/connector.c +++ b/drivers/connector/connector.c @@ -157,17 +157,18 @@ static int cn_call_callback(struct sk_buff *skb) static void cn_rx_skb(struct sk_buff *__skb) { struct nlmsghdr *nlh; - int err; struct sk_buff *skb; + int len, err; skb = skb_get(__skb); if (skb->len >= NLMSG_HDRLEN) { nlh = nlmsg_hdr(skb); + len = nlmsg_len(nlh); - if (nlh->nlmsg_len < sizeof(struct cn_msg) || + if (len < (int)sizeof(struct cn_msg) || skb->len < nlh->nlmsg_len || - nlh->nlmsg_len > CONNECTOR_MAX_MSG_SIZE) { + len > CONNECTOR_MAX_MSG_SIZE) { kfree_skb(skb); return; } -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] connector: use 'size' everywhere in cn_netlink_send() 2013-09-30 20:03 [PATCH 0/4] connector fixes Mathias Krause 2013-09-30 20:03 ` [PATCH 1/4] proc connector: fix info leaks Mathias Krause 2013-09-30 20:03 ` [PATCH 2/4] connector: use nlmsg_len() to check message length Mathias Krause @ 2013-09-30 20:03 ` Mathias Krause 2013-09-30 20:03 ` [PATCH 4/4] connector - documentation: simplify netlink message length assignment Mathias Krause 2013-10-02 20:04 ` [PATCH 0/4] connector fixes David Miller 4 siblings, 0 replies; 7+ messages in thread From: Mathias Krause @ 2013-09-30 20:03 UTC (permalink / raw) To: Evgeniy Polyakov; +Cc: Mathias Krause, netdev We calculated the size for the netlink message buffer as size. Use size in the memcpy() call as well instead of recalculating it. Signed-off-by: Mathias Krause <minipli@googlemail.com> --- drivers/connector/connector.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/connector/connector.c b/drivers/connector/connector.c index 0daa11e..a36749f 100644 --- a/drivers/connector/connector.c +++ b/drivers/connector/connector.c @@ -109,7 +109,7 @@ int cn_netlink_send(struct cn_msg *msg, u32 __group, gfp_t gfp_mask) data = nlmsg_data(nlh); - memcpy(data, msg, sizeof(*data) + msg->len); + memcpy(data, msg, size); NETLINK_CB(skb).dst_group = group; -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] connector - documentation: simplify netlink message length assignment 2013-09-30 20:03 [PATCH 0/4] connector fixes Mathias Krause ` (2 preceding siblings ...) 2013-09-30 20:03 ` [PATCH 3/4] connector: use 'size' everywhere in cn_netlink_send() Mathias Krause @ 2013-09-30 20:03 ` Mathias Krause 2013-10-02 20:04 ` [PATCH 0/4] connector fixes David Miller 4 siblings, 0 replies; 7+ messages in thread From: Mathias Krause @ 2013-09-30 20:03 UTC (permalink / raw) To: Evgeniy Polyakov; +Cc: Mathias Krause, netdev Use the precalculated size instead of obfuscating the message length calculation by first subtracting the netlink header length from size and then use the NLMSG_LENGTH() macro to add it back again. Signed-off-by: Mathias Krause <minipli@googlemail.com> --- Documentation/connector/ucon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/connector/ucon.c b/Documentation/connector/ucon.c index 4848db8..8a4da64 100644 --- a/Documentation/connector/ucon.c +++ b/Documentation/connector/ucon.c @@ -71,7 +71,7 @@ static int netlink_send(int s, struct cn_msg *msg) nlh->nlmsg_seq = seq++; nlh->nlmsg_pid = getpid(); nlh->nlmsg_type = NLMSG_DONE; - nlh->nlmsg_len = NLMSG_LENGTH(size - sizeof(*nlh)); + nlh->nlmsg_len = size; nlh->nlmsg_flags = 0; m = NLMSG_DATA(nlh); -- 1.7.10.4 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/4] connector fixes 2013-09-30 20:03 [PATCH 0/4] connector fixes Mathias Krause ` (3 preceding siblings ...) 2013-09-30 20:03 ` [PATCH 4/4] connector - documentation: simplify netlink message length assignment Mathias Krause @ 2013-10-02 20:04 ` David Miller 2013-10-06 20:46 ` Рустафа Джамурахметов 4 siblings, 1 reply; 7+ messages in thread From: David Miller @ 2013-10-02 20:04 UTC (permalink / raw) To: minipli; +Cc: zbr, netdev From: Mathias Krause <minipli@googlemail.com> Date: Mon, 30 Sep 2013 22:03:05 +0200 > This series fixes a few netlink related issues of the connector interface. > > The first two patches are bug fixes. The last two are cleanups. > > Please apply! Series applied and first two patches queued up for -stable, thanks. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/4] connector fixes 2013-10-02 20:04 ` [PATCH 0/4] connector fixes David Miller @ 2013-10-06 20:46 ` Рустафа Джамурахметов 0 siblings, 0 replies; 7+ messages in thread From: Рустафа Джамурахметов @ 2013-10-06 20:46 UTC (permalink / raw) To: David Miller, minipli@googlemail.com; +Cc: netdev@vger.kernel.org 03.10.2013, 00:04, "David Miller" <davem@davemloft.net>: > From: Mathias Krause <minipli@googlemail.com> > Date: Mon, 30 Sep 2013 22:03:05 +0200 > >> This series fixes a few netlink related issues of the connector interface. >> >> The first two patches are bug fixes. The last two are cleanups. >> >> Please apply! > > Series applied and first two patches queued up for -stable, thanks. Thank you. ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-10-06 20:46 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2013-09-30 20:03 [PATCH 0/4] connector fixes Mathias Krause 2013-09-30 20:03 ` [PATCH 1/4] proc connector: fix info leaks Mathias Krause 2013-09-30 20:03 ` [PATCH 2/4] connector: use nlmsg_len() to check message length Mathias Krause 2013-09-30 20:03 ` [PATCH 3/4] connector: use 'size' everywhere in cn_netlink_send() Mathias Krause 2013-09-30 20:03 ` [PATCH 4/4] connector - documentation: simplify netlink message length assignment Mathias Krause 2013-10-02 20:04 ` [PATCH 0/4] connector fixes David Miller 2013-10-06 20:46 ` Рустафа Джамурахметов
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox