Received: by 10.213.65.68 with SMTP id h4csp1800199imn; Thu, 29 Mar 2018 11:15:31 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/CNV2/g8ZmK512jmPzrKrf+8rYDD3VaGsi4rqiQ3YDcP2J/aNU8cFtxz78XAP+8dG2dhDB X-Received: by 10.98.139.143 with SMTP id e15mr7290288pfl.134.1522347331539; Thu, 29 Mar 2018 11:15:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522347331; cv=none; d=google.com; s=arc-20160816; b=f/7ErjfxfVL/UFylnWegWL7nxHtv4HLaBYdHXlb+BP5tBuWOqR8VO4Tw+D1FnUKZLV F4KjtRuiwW2MMStnEb0wCzGWSBuXjJzUoNX0805GjDdZV1eSzlOOGNm6kvT4ufX0KMor hNbfFPCKQE8aHc058xQHQYROc4XYPoCu+krXe+B88Y5JH1waCcWpZbLsH3D+g5iCN/hv +GcuwK1tYt49IQG+son98WzKTDWVtgMjHZvv9lzx5hW4OjLzIu0dbiuVD3/k0Wt3E7Oy m1ZTHZ4ZhCCMhq4vxnWiBrlRjrkZLd7+JJuv2CS+OY/kFgdLnHegtd7FHQke9afWkrxo D+hg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=kmCC55iEPPTQdmKoTutWc9sB0kYt4UTnva6lS2QI26I=; b=eZyx3VEmyapBhgM/IoIAZuFfj51VyN79wOmhJ9e4CxpYCD9n+1R7egFRYSA8D0hbwz Kv5B1ZX2Sfg15jZRsnBfuS4Jg9978muLYIHprRsiYx+nK/gkBBqDqe2m3RwyraKHG/OV kzCTKvC25G4DJmD+Q6OPg1WqBWlJQff0pVouxSQdKZfb0o5lynrdlg/lSkokDtk3mNNO 13+4jn26zrQAdkWbvboxuckrRfzjhoQWH9kY91D4q3M3FFqWNNSYaPWCV5ZCOBBI6MAR VbLofWamEYQwZGsOAQ2BdJBfiPEhpv1J6fJju84Y/eHedTFuelXqFo/iRbZrTbPGa7AR NUkg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n5si4342662pgs.106.2018.03.29.11.15.17; Thu, 29 Mar 2018 11:15:31 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754056AbeC2SHc (ORCPT + 99 others); Thu, 29 Mar 2018 14:07:32 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:59982 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753903AbeC2SHY (ORCPT ); Thu, 29 Mar 2018 14:07:24 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 1CE5BA80; Thu, 29 Mar 2018 18:07:23 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , Andrei Vagin , "David S. Miller" Subject: [PATCH 4.9 08/28] net: use skb_to_full_sk() in skb_update_prio() Date: Thu, 29 Mar 2018 20:00:27 +0200 Message-Id: <20180329175734.474910176@linuxfoundation.org> X-Mailer: git-send-email 2.16.3 In-Reply-To: <20180329175733.447823703@linuxfoundation.org> References: <20180329175733.447823703@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Eric Dumazet [ Upstream commit 4dcb31d4649df36297296b819437709f5407059c ] Andrei Vagin reported a KASAN: slab-out-of-bounds error in skb_update_prio() Since SYNACK might be attached to a request socket, we need to get back to the listener socket. Since this listener is manipulated without locks, add const qualifiers to sock_cgroup_prioidx() so that the const can also be used in skb_update_prio() Also add the const qualifier to sock_cgroup_classid() for consistency. Fixes: ca6fb0651883 ("tcp: attach SYNACK messages to request sockets instead of listener") Signed-off-by: Eric Dumazet Reported-by: Andrei Vagin Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/linux/cgroup-defs.h | 4 ++-- net/core/dev.c | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -609,13 +609,13 @@ struct sock_cgroup_data { * updaters and return part of the previous pointer as the prioidx or * classid. Such races are short-lived and the result isn't critical. */ -static inline u16 sock_cgroup_prioidx(struct sock_cgroup_data *skcd) +static inline u16 sock_cgroup_prioidx(const struct sock_cgroup_data *skcd) { /* fallback to 1 which is always the ID of the root cgroup */ return (skcd->is_data & 1) ? skcd->prioidx : 1; } -static inline u32 sock_cgroup_classid(struct sock_cgroup_data *skcd) +static inline u32 sock_cgroup_classid(const struct sock_cgroup_data *skcd) { /* fallback to 0 which is the unconfigured default classid */ return (skcd->is_data & 1) ? skcd->classid : 0; --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3179,15 +3179,23 @@ static inline int __dev_xmit_skb(struct #if IS_ENABLED(CONFIG_CGROUP_NET_PRIO) static void skb_update_prio(struct sk_buff *skb) { - struct netprio_map *map = rcu_dereference_bh(skb->dev->priomap); + const struct netprio_map *map; + const struct sock *sk; + unsigned int prioidx; - if (!skb->priority && skb->sk && map) { - unsigned int prioidx = - sock_cgroup_prioidx(&skb->sk->sk_cgrp_data); + if (skb->priority) + return; + map = rcu_dereference_bh(skb->dev->priomap); + if (!map) + return; + sk = skb_to_full_sk(skb); + if (!sk) + return; - if (prioidx < map->priomap_len) - skb->priority = map->priomap[prioidx]; - } + prioidx = sock_cgroup_prioidx(&sk->sk_cgrp_data); + + if (prioidx < map->priomap_len) + skb->priority = map->priomap[prioidx]; } #else #define skb_update_prio(skb)