From mboxrd@z Thu Jan 1 00:00:00 1970 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.3 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,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 019B7C4320A for ; Sat, 7 Aug 2021 06:42:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE62A610FF for ; Sat, 7 Aug 2021 06:42:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231373AbhHGGmD (ORCPT ); Sat, 7 Aug 2021 02:42:03 -0400 Received: from relay.sw.ru ([185.231.240.75]:48474 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230297AbhHGGmC (ORCPT ); Sat, 7 Aug 2021 02:42:02 -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:From: Subject; bh=Y0aAjMVRc2eMCd5br2aos6hJsJXTCYbOLMiB+Wn43ow=; b=mweOF5glY4Bj4Go5i Jm0sx5N4aSZowSnbwDmH49ln3HofW+0xGQyxHl8sMrlBphr9ILU1+h0OE3+scf81O9xYR4/nl73Xs cnveq2wTplnJ5r91kPqWq9202QD7CeKyuqvDU9C4mfB/KlYmMjd+Hm1PCDQM9CZqA0X5Q2rP8Hc+U =; Received: from [10.93.0.56] by relay.sw.ru with esmtp (Exim 4.94.2) (envelope-from ) id 1mCG1b-006hh6-BY; Sat, 07 Aug 2021 09:41:39 +0300 Subject: Re: [PATCH NET] vrf: fix null pointer dereference in vrf_finish_output() To: Jakub Kicinski Cc: "David S. Miller" , Hideaki YOSHIFUJI , David Ahern , Eric Dumazet , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@openvz.org, Julian Wiedmann References: <20210806.111412.1329682129695306949.davem@davemloft.net> <5ba67c28-1056-e24d-cad3-4b7aaac01111@virtuozzo.com> <20210806154227.49ac089d@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> From: Vasily Averin Message-ID: <11bb7d25-71e2-c49a-4754-8daa52150adb@virtuozzo.com> Date: Sat, 7 Aug 2021 09:41:38 +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: <20210806154227.49ac089d@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/7/21 1:42 AM, Jakub Kicinski wrote: > On Fri, 6 Aug 2021 15:53:00 +0300 Vasily Averin wrote: >> 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 > > Thanks for following up! I decided to pick a similar patch from Dan > Carpenter [1] because the chunk quoted below is not really necessary. I still think that my patch version is preferable. It's better to use vrf_tx_error(dev, skb) because: a) both rollbacks can use the same net device b) probably using 'dev' allows to avoid an extra pointer dereference. Originally, i.e. before fixed patch 14ee70ca89e6, rollback after failed header expand called the save vrf_tx_error() call. This function does 2 things: - increments stats.tx_errors on specified network device - frees provided skb. Commit 14ee70ca89e6 replaced skb_realloc_headroom() by skb_expand_head() that frees skb inside, So vrf_tx_error() call on rollback was replaced with direct increment of stats.tx_errors. We cannot use now original skb->dev so our fixup patches replaces it with dev variable already used in this function. Though, if we should use the same net device in both rollbacks. It's illogical for me to change one place and do not change another one. If we follow to your decision -- it isn't a problem. skb->dev and skb should be identical. Though 'skb->dev' does an extra dereference, while dev was used in function and probably was saved to register. Thank you, Vasily Averin > [1] https://lore.kernel.org/kernel-janitors/20210806150435.GB15586@kili/ > >> @@ -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; >> } >> >