From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D70D7BAFF; Wed, 21 Feb 2024 14:07:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708524421; cv=none; b=Smxx8/fAd0l5Rhfyync94upLOBa2ZlCVNoxjzcD7mtDqa0YyoyJ1+FmKNuEntcZ81iAvisuD5TNYh3+Tm1C+08viaMfBskKyVI0ABlaHqKq4uOfYGx2ZGaTnOGLF7gOqwdSdVOfgrQtsLhpyFe+C+PNHHxLC5kXfwAq9NXc3bfw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708524421; c=relaxed/simple; bh=WnRnFHhXbc9asXD+OO0+Q/SuxlUuhXd1q51qXSwH/v0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fD7Vy4xwSd8J8fWEJ4lBi6XJv6iNbyP/qg4tg6zpYcT4jBdDT9WIdSZ88Y1EiFvPFdwUB9Plmpq0F3H18FziDxMSf1zMtzn1Ep26E1oIAE6t9cUwEHvQ+b0l8whIFBr475N5mq1rPtTkDsKDf3ifQEpvDBbItF42lCDeaNktWgU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=OiGFJUVB; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="OiGFJUVB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A0963C433F1; Wed, 21 Feb 2024 14:07:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708524421; bh=WnRnFHhXbc9asXD+OO0+Q/SuxlUuhXd1q51qXSwH/v0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OiGFJUVB9TwWybFQljQZbQg+k//P1q5OOvSYkcEo8yb09oD3w5QwykQN84MJOvmap QmcoKvDyu5ywlG7s3p/Hrw53ZFbX67+/LOO4Z7nbDy/MHQ0dQmwr2Xromq/9qHMbCF exP5vSuBa4LquKKp+c7oZbf1VuGe+o4xR5+OM8VY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhipeng Lu , Eric Dumazet , Jakub Kicinski , Sasha Levin Subject: [PATCH 5.10 238/379] net: ipv4: fix a memleak in ip_setup_cork Date: Wed, 21 Feb 2024 14:06:57 +0100 Message-ID: <20240221130001.954082917@linuxfoundation.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240221125954.917878865@linuxfoundation.org> References: <20240221125954.917878865@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhipeng Lu [ Upstream commit 5dee6d6923458e26966717f2a3eae7d09fc10bf6 ] When inetdev_valid_mtu fails, cork->opt should be freed if it is allocated in ip_setup_cork. Otherwise there could be a memleak. Fixes: 501a90c94510 ("inet: protect against too small mtu values.") Signed-off-by: Zhipeng Lu Reviewed-by: Eric Dumazet Link: https://lore.kernel.org/r/20240129091017.2938835-1-alexious@zju.edu.cn Signed-off-by: Jakub Kicinski Signed-off-by: Sasha Levin --- net/ipv4/ip_output.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/net/ipv4/ip_output.c b/net/ipv4/ip_output.c index a99c374101fc..12ee857d6cfe 100644 --- a/net/ipv4/ip_output.c +++ b/net/ipv4/ip_output.c @@ -1260,6 +1260,12 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork, if (unlikely(!rt)) return -EFAULT; + cork->fragsize = ip_sk_use_pmtu(sk) ? + dst_mtu(&rt->dst) : READ_ONCE(rt->dst.dev->mtu); + + if (!inetdev_valid_mtu(cork->fragsize)) + return -ENETUNREACH; + /* * setup for corking. */ @@ -1276,12 +1282,6 @@ static int ip_setup_cork(struct sock *sk, struct inet_cork *cork, cork->addr = ipc->addr; } - cork->fragsize = ip_sk_use_pmtu(sk) ? - dst_mtu(&rt->dst) : READ_ONCE(rt->dst.dev->mtu); - - if (!inetdev_valid_mtu(cork->fragsize)) - return -ENETUNREACH; - cork->gso_size = ipc->gso_size; cork->dst = &rt->dst; -- 2.43.0