Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp3225172rwd; Mon, 22 May 2023 10:18:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4VnBUnzeRVzFAkl9xWXCAdVOjal4CYMcQ0jZSB/C7QnHO9ovbuERLfOJT78X97+/3YOEYq X-Received: by 2002:a17:90a:49c6:b0:255:49c0:2618 with SMTP id l6-20020a17090a49c600b0025549c02618mr6084109pjm.39.1684775930705; Mon, 22 May 2023 10:18:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684775930; cv=none; d=google.com; s=arc-20160816; b=vPjIZazjVb0UQnEGpni4K+Pa7kPGC2HMGTEuTqC2CJab4wMO+oNktQ8d5Wq4O68ORB JZTtvI7974u22JBmbmGzmPWoP0et8zJk7S7wGo68aXTEtnj0JqoVVcfVh5BvO+fxsYlr TZlG8hdLEyuNjvqq37JwczeP5qavcFSynhk4WnPDKVjO/g31icf2gMpL6hNqUB6Dc4by ppSF9w4XxREHNcX5UOkJ+1RG8SNn3dT+9zpOGX6bVRiABXbldpKG6fjFuo+frHwAqivN Lzst+sL0pd3wbs27Gz3k2cYTa5+e5Y6SxgwPcE6PIfivtmfRa44zezm2ilgfdMFM//Kf 2qcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6KDfEFqSBnYdsid/7pFRx/XFDPDSUTDfpLUrg25dLLw=; b=PdlDE1J/2WbP+DBo0C1vZk/lryng1xh7WEbvrX0vMlgPG/wR56suK43wNLNyBwm5QX 3GS1SzBhUKnzFArHr5C8MsfPkFaxASzwQHoXcjMe2oLUppHSuxI+WVDeGTP1ej2U8zRd JtE5HtUApz5qydpVu9n2gImnKwM+HUthEyhENilxTaDT92pfjPYS8s9xHPGpQak6lO07 To1ldvv+MPhYCDHyBuPSHQokUUtOnjNOTmeJaf+nfTIAOYizd+ntlv0/6ZmEKDeb1DF8 AqhvLLQOEGJvPs6lkv7Yi5Lt8psULyUPFddSpdWihby87F9XVtJxmgpgj1uGECEn1jbT /usg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S6ZxzaCe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cm20-20020a17090afa1400b00252ad7ab4a5si7072947pjb.5.2023.05.22.10.18.37; Mon, 22 May 2023 10:18:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S6ZxzaCe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231919AbjEVQzL (ORCPT + 99 others); Mon, 22 May 2023 12:55:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229796AbjEVQzJ (ORCPT ); Mon, 22 May 2023 12:55:09 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1F6793 for ; Mon, 22 May 2023 09:55:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 89995614B3 for ; Mon, 22 May 2023 16:55:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20C77C433D2; Mon, 22 May 2023 16:55:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1684774507; bh=vkAlwsQMx2wZNoXGzlwhaRS7dm4lCOLkXVDx8xGJ3QY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S6ZxzaCe0ikG/2Rj3oLs0VQA3AEkydLg7ymC0nDJwmwsgtVbwMTqeugWRVbSmnTov 4+7X84zzR/ZLUQGIjMl3GQvWJxmanZTHPmL7vLBUIG+1D6MbV3/rcA11GUm0nF161B y8aSkXNKCD/OqIKPKxB2MJaDImIMNB0tPbVzX1iXixpmh5B607+m6h+DuKJhhXf9so 2hF61GaU0qaFvcyHiaDbO+wEEq9TO6l0ENrOEl2M/yRuLlfSMefTEkb1d4PDqUp+Dc qL6y8f7sq7GvDMoD75yybkrZFbYc0Qii66y+rBfsBtQbjycPUAALhrntK/J+MrCtT+ MiI63dT4bnd8Q== From: SeongJae Park To: Pratyush Yadav Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Kuniyuki Iwashima , Willem de Bruijn , Norbert Manthey , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH net] net: fix skb leak in __skb_tstamp_tx() Date: Mon, 22 May 2023 16:55:05 +0000 Message-Id: <20230522165505.90105-1-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230522153020.32422-1-ptyadav@amazon.de> References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Pratyush, On Mon, 22 May 2023 17:30:20 +0200 Pratyush Yadav wrote: > Commit 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with > TX timestamp.") added a call to skb_orphan_frags_rx() to fix leaks with > zerocopy skbs. But it ended up adding a leak of its own. When > skb_orphan_frags_rx() fails, the function just returns, leaking the skb > it just cloned. Free it before returning. > > This bug was discovered and resolved using Coverity Static Analysis > Security Testing (SAST) by Synopsys, Inc. > > Fixes: 50749f2dd685 ("tcp/udp: Fix memleaks of sk and zerocopy skbs with TX timestamp.") Seems the commit has merged in several stable kernels. Is the bug also affecting those? If so, would it be better to Cc stable@vger.kernel.org? Thanks, SJ > Signed-off-by: Pratyush Yadav > --- > > I do not know this code very well, this was caught by our static > analysis tool. I did not try specifically reproducing the leak but I did > do a boot test by adding this patch on 6.4-rc3 and the kernel boots > fine. > > net/core/skbuff.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/net/core/skbuff.c b/net/core/skbuff.c > index 515ec5cdc79c..cea28d30abb5 100644 > --- a/net/core/skbuff.c > +++ b/net/core/skbuff.c > @@ -5224,8 +5224,10 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb, > } else { > skb = skb_clone(orig_skb, GFP_ATOMIC); > > - if (skb_orphan_frags_rx(skb, GFP_ATOMIC)) > + if (skb_orphan_frags_rx(skb, GFP_ATOMIC)) { > + kfree_skb(skb); > return; > + } > } > if (!skb) > return; > -- > 2.39.2 >