Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1261828pxb; Fri, 22 Jan 2021 10:52:12 -0800 (PST) X-Google-Smtp-Source: ABdhPJwn+Zzx39HHmZ/uMk+BtTD7eKMIezgHma0P0Qirxtmf6w+WmXST8LlY25HHdCDV17zIA85a X-Received: by 2002:a50:fe86:: with SMTP id d6mr4332765edt.80.1611341532219; Fri, 22 Jan 2021 10:52:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611341532; cv=none; d=google.com; s=arc-20160816; b=cZoXaf76eghB9n0XGSe3997SBrR37+wjKpgSR4JVbGbg20/wHGU9Y+EqRyUGTlK5iN ZnovQAgBjKd54sTXcnmMrYtoZCOGYJZ86Sh36WYf+vmBUL8wkTp3aqUKsGoH91dORhMa i3/nsbbxoS/uIYJYgqgKGjDBEz/kM72U0+u2e65FLLxGVkMQDYh+MPoEFckN40DQrgWs wCXsm2aCN7GumCf0R78YI8SV/dQbMpGR0aXlBLHi8bEvz5UsflBieI1btjE/nsrwfr2w 4avsjKSNp5a8Bc4Ixxx+gjrDBiGgq7NGtbLyV9NCZhreWXHJYdqipqgW0AgojTiFyvM8 0XpQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5iNdYdgXxitqMTx8QHmR75VbVMsI0GuP7iH7NeeXEqI=; b=WiBLMWDqTylYN/MWdRaFpb73uEGd1GWW1cycNDDighMjz+hdmvH86C7XIIHqA6M05T lkxX7sLxbbbdobNAKuXphLPnb9+1OrBNdJUY6vX/m2nzlI5Kt1FWlqsCtLOLZZXo3GZH g6huclhVX4VaDxseHKPB/JSyO/dPd6ZBTVumwMVIJk14mi+bwMdk2j7GG1CcP7HCAiOI aSTI9k7eDVsexIyvEnNSU1Dk3bhdad9P5WuwvBDuWHfTBeK9TKSLVJ58RzlCvYnty6tL 70xH9Aulk6hUDntaxtMa5RxTab7ubciJu3hs+Nnd2FLW6aO0GQBHEjmJJBNtCL6/mYyW 4KVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="F++r2/3G"; 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=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b6si4212801edu.567.2021.01.22.10.51.47; Fri, 22 Jan 2021 10:52:12 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b="F++r2/3G"; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730201AbhAVSuN (ORCPT + 99 others); Fri, 22 Jan 2021 13:50:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:38816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728552AbhAVOWp (ORCPT ); Fri, 22 Jan 2021 09:22:45 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8015923B6A; Fri, 22 Jan 2021 14:16:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1611324995; bh=NW0j9xkeE8PAdFRoCqVYZ135xURObUv492Mtof7FZ1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F++r2/3GM8qBouyClp200Nvs0leP+z1I9u7wZNJF1ZtuWs6/Z7CXb4u0Qo8goploP 6XF+swxNl19hr6l0z9oNXWQLsaXWFs+PxoBrHcWmS1OlwciA0fkxb+w7o+KKlHfqzu 7DmBxnlS8CRsADLj8E1OIGZqe+571VSfB+PoGt2A= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Martin KaFai Lau , Stanislav Fomichev , Daniel Borkmann Subject: [PATCH 5.4 10/33] bpf: Dont leak memory in bpf getsockopt when optlen == 0 Date: Fri, 22 Jan 2021 15:12:26 +0100 Message-Id: <20210122135733.995410579@linuxfoundation.org> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210122135733.565501039@linuxfoundation.org> References: <20210122135733.565501039@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Stanislav Fomichev commit 4be34f3d0731b38a1b24566b37fbb39500aaf3a2 upstream. optlen == 0 indicates that the kernel should ignore BPF buffer and use the original one from the user. We, however, forget to free the temporary buffer that we've allocated for BPF. Fixes: d8fe449a9c51 ("bpf: Don't return EINVAL from {get,set}sockopt when optlen > PAGE_SIZE") Reported-by: Martin KaFai Lau Signed-off-by: Stanislav Fomichev Signed-off-by: Daniel Borkmann Acked-by: Martin KaFai Lau Link: https://lore.kernel.org/bpf/20210112162829.775079-1-sdf@google.com Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/cgroup.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -1057,12 +1057,13 @@ int __cgroup_bpf_run_filter_setsockopt(s if (ctx.optlen != 0) { *optlen = ctx.optlen; *kernel_optval = ctx.optval; + /* export and don't free sockopt buf */ + return 0; } } out: - if (ret) - sockopt_free_buf(&ctx); + sockopt_free_buf(&ctx); return ret; } EXPORT_SYMBOL(__cgroup_bpf_run_filter_setsockopt);