Commit 2309236c authored by Konstantin Khlebnikov's avatar Konstantin Khlebnikov Committed by David S. Miller

cls_cgroup: get sk_classid only from full sockets

skb->sk could point to timewait or request socket which has no sk_classid.
Detected as "BUG: KASAN: slab-out-of-bounds in cls_cgroup_classify".
Signed-off-by: default avatarKonstantin Khlebnikov <khlebnikov@yandex-team.ru>
Acked-by: default avatarEric Dumazet <edumazet@google.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 851b10d6
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/hardirq.h> #include <linux/hardirq.h>
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
#include <net/sock.h> #include <net/sock.h>
#include <net/inet_sock.h>
#ifdef CONFIG_CGROUP_NET_CLASSID #ifdef CONFIG_CGROUP_NET_CLASSID
struct cgroup_cls_state { struct cgroup_cls_state {
...@@ -63,11 +64,13 @@ static inline u32 task_get_classid(const struct sk_buff *skb) ...@@ -63,11 +64,13 @@ static inline u32 task_get_classid(const struct sk_buff *skb)
* softirqs always disables bh. * softirqs always disables bh.
*/ */
if (in_serving_softirq()) { if (in_serving_softirq()) {
struct sock *sk = skb_to_full_sk(skb);
/* If there is an sock_cgroup_classid we'll use that. */ /* If there is an sock_cgroup_classid we'll use that. */
if (!skb->sk) if (!sk || !sk_fullsock(sk))
return 0; return 0;
classid = sock_cgroup_classid(&skb->sk->sk_cgrp_data); classid = sock_cgroup_classid(&sk->sk_cgrp_data);
} }
return classid; return classid;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment