From patchwork Fri Aug 6 12:53:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasily Averin X-Patchwork-Id: 12423445 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B176C4338F for ; Fri, 6 Aug 2021 12:53:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F0EDE611C3 for ; Fri, 6 Aug 2021 12:53:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243408AbhHFMxY (ORCPT ); Fri, 6 Aug 2021 08:53:24 -0400 Received: from relay.sw.ru ([185.231.240.75]:41218 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237819AbhHFMxX (ORCPT ); Fri, 6 Aug 2021 08:53:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=virtuozzo.com; s=relay; h=Content-Type:MIME-Version:Date:Message-ID:Subject :From; bh=egBPXyBYmGMlQBMUmRxl2nc+0PbWoNUPh+wMswC6yd4=; b=AuK5kyS3mA76tNw1Fct ZqfO1tGW+lcwp2ncETtRW4TbOyO2yZst7jE4/LBrZptROaBA6fiUKHH5ih3316PPWBI+xm9Q+4aUn qUAjsXjZO6OeTPq/h45BQXP94noSvi+13ud0UxsJ5Eebvtsr0vO/fjyKpZBLSr3/gg6Fyk8P27c=; Received: from [10.93.0.56] by relay.sw.ru with esmtp (Exim 4.94.2) (envelope-from ) id 1mBzLR-006co5-Af; Fri, 06 Aug 2021 15:53:01 +0300 From: Vasily Averin Subject: [PATCH NET] vrf: fix null pointer dereference in vrf_finish_output() To: "David S. Miller" , Hideaki YOSHIFUJI , David Ahern , Jakub Kicinski , Eric Dumazet Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@openvz.org, Julian Wiedmann References: <20210806.111412.1329682129695306949.davem@davemloft.net> Message-ID: <5ba67c28-1056-e24d-cad3-4b7aaac01111@virtuozzo.com> Date: Fri, 6 Aug 2021 15:53:00 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210806.111412.1329682129695306949.davem@davemloft.net> Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org After 14ee70ca89e6 ("vrf: use skb_expand_head in vrf_finish_output") skb->dev is accessed after skb free. Let's replace skb->dev by dev = skb_dst(skb)->dev: vrf_finish_output() is only called from vrf_output(), it set skb->dev to skb_dst(skb)->dev and calls POSTROUTING netfilter hooks, where output device should not be changed. Fixes: 14ee70ca89e6 ("vrf: use skb_expand_head in vrf_finish_output") Reported-by: Julian Wiedmann Signed-off-by: Vasily Averin --- drivers/net/vrf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/vrf.c b/drivers/net/vrf.c index 726adf0..168d4ef 100644 --- a/drivers/net/vrf.c +++ b/drivers/net/vrf.c @@ -864,7 +864,7 @@ static int vrf_finish_output(struct net *net, struct sock *sk, struct sk_buff *s if (unlikely(skb_headroom(skb) < hh_len && dev->header_ops)) { skb = skb_expand_head(skb, hh_len); if (!skb) { - skb->dev->stats.tx_errors++; + dev->stats.tx_errors++; return -ENOMEM; } } @@ -883,7 +883,7 @@ static int vrf_finish_output(struct net *net, struct sock *sk, struct sk_buff *s } rcu_read_unlock_bh(); - vrf_tx_error(skb->dev, skb); + vrf_tx_error(dev, skb); return -EINVAL; }