Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1480529pxb; Sun, 12 Sep 2021 21:06:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrMpzFJBFEDr+kgy8h3PKO5G/AOd0Yov6aXg5/Oe9Bum1r8hBA7xasZvX7D3KD9ZS94he1 X-Received: by 2002:a02:7355:: with SMTP id a21mr7875532jae.53.1631506007625; Sun, 12 Sep 2021 21:06:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631506007; cv=none; d=google.com; s=arc-20160816; b=pIvRgTcN4Gn39FnphbFu2TeP5LGwu+DIbhAEwFlwZqDmkXqiAdNxopGi9VQUc7ZF5t 6qyD3sOI/CAZoj4EKxfB8fZmwuyTo/G3rWXcaDTeGpQYyFNNcj6efCeSfgmgcnJOojYR Yi/xkrpsIN2b3j5QMHj4GLTR2J8zJcBFasmmf8/+OgLdRR+jyUion1PBqbdgDxnakM5L 8dbdwQRYcTHwoJhK7Ml+Yl72vG8wzDx4XS1K1pYk7MCR8dxDqgFLIf4ilZsrdNsigMeU kbChrRCsWu+wRnUw2ejLhKaOUesV05Y0z4OVTgvKKFEU6FVR6IGPtQJoySE54U9IS8gT AKaA== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=dDi0EBey+fTk+gMxs/hbMAsZ2CO16dXmIG7oQmqFe8A=; b=v7IzSmNf/SEzw8H/rVt2k17Iul5bd/d35R14fDu6Ghk8PRuQvEiYdvGiwNmqU1Zid7 Foc79AZCGBUPDHdW1lo5uoD/22VTPWE+Exs6NdXa+DXHz8J+/pewLV+xeHPRd83/2P67 9/EYoqgIeNZhT7L5UB0tSFJeQn5FBWoh1aixQdzMZQFU5H57hxSK07ztRT1ziOefWVa3 pG443sARSZEicTVAzkWbTPcV87QekrwdpgSB8ypN66KO+YoIfV0Kg6uM6yjz7jPHJzYh sACGaISTERFopj6OdfDPI5vZIwy74ULClfha+mJQvi4rRhln60Ec8FRvTEAf01ttsRWr NvXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=cKMmrn9h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k12si6092273jac.101.2021.09.12.21.06.23; Sun, 12 Sep 2021 21:06:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=cKMmrn9h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230375AbhIMEGS (ORCPT + 99 others); Mon, 13 Sep 2021 00:06:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229563AbhIMEGR (ORCPT ); Mon, 13 Sep 2021 00:06:17 -0400 Received: from out0.migadu.com (out0.migadu.com [IPv6:2001:41d0:2:267::]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 416F4C061574 for ; Sun, 12 Sep 2021 21:04:59 -0700 (PDT) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1631505896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=dDi0EBey+fTk+gMxs/hbMAsZ2CO16dXmIG7oQmqFe8A=; b=cKMmrn9huapcnUmubkdisNXNbhQlWCXmDlVuLqmofy44yzsjPddlQy/hOxGWcqlogPidJA Deb0UNOOmpqbmHAlRj0b1CwZKHuDdEETtXThRPxf5eVm38fhqivt0FO1ED7Gi1+L+VvGQF 9wb1/1yTkkLL1BgImVvE4uHiNnph90w= From: Yajun Deng To: davem@davemloft.net, yoshfuji@linux-ipv6.org, dsahern@kernel.org, kuba@kernel.org Cc: edumazet@google.com, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Yajun Deng Subject: [PATCH] Revert "ipv4: fix memory leaks in ip_cmsg_send() callers" Date: Mon, 13 Sep 2021 12:04:42 +0800 Message-Id: <20210913040442.2627-1-yajun.deng@linux.dev> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: yajun.deng@linux.dev Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This reverts commit 919483096bfe75dda338e98d56da91a263746a0a. There is only when ip_options_get() return zero need to free. It already called kfree() when return error. Fixes: 919483096bfe ("ipv4: fix memory leaks in ip_cmsg_send() callers") Signed-off-by: Yajun Deng --- net/ipv4/ip_sockglue.c | 2 +- net/ipv4/ping.c | 5 ++--- net/ipv4/raw.c | 5 ++--- net/ipv4/udp.c | 5 ++--- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c index b297bb28556e..7cef9987ab4a 100644 --- a/net/ipv4/ip_sockglue.c +++ b/net/ipv4/ip_sockglue.c @@ -279,7 +279,7 @@ int ip_cmsg_send(struct sock *sk, struct msghdr *msg, struct ipcm_cookie *ipc, case IP_RETOPTS: err = cmsg->cmsg_len - sizeof(struct cmsghdr); - /* Our caller is responsible for freeing ipc->opt */ + /* Our caller is responsible for freeing ipc->opt when err = 0 */ err = ip_options_get(net, &ipc->opt, KERNEL_SOCKPTR(CMSG_DATA(cmsg)), err < 40 ? err : 40); diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c index 1e44a43acfe2..c588f9f2f46c 100644 --- a/net/ipv4/ping.c +++ b/net/ipv4/ping.c @@ -727,10 +727,9 @@ static int ping_v4_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (msg->msg_controllen) { err = ip_cmsg_send(sk, msg, &ipc, false); - if (unlikely(err)) { - kfree(ipc.opt); + if (unlikely(err)) return err; - } + if (ipc.opt) free = 1; } diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c index bb446e60cf58..1c98063a3ae8 100644 --- a/net/ipv4/raw.c +++ b/net/ipv4/raw.c @@ -562,10 +562,9 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (msg->msg_controllen) { err = ip_cmsg_send(sk, msg, &ipc, false); - if (unlikely(err)) { - kfree(ipc.opt); + if (unlikely(err)) goto out; - } + if (ipc.opt) free = 1; } diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 8851c9463b4b..d5f5981d7a43 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1122,10 +1122,9 @@ int udp_sendmsg(struct sock *sk, struct msghdr *msg, size_t len) if (err > 0) err = ip_cmsg_send(sk, msg, &ipc, sk->sk_family == AF_INET6); - if (unlikely(err < 0)) { - kfree(ipc.opt); + if (unlikely(err < 0)) return err; - } + if (ipc.opt) free = 1; connected = 0; -- 2.32.0