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=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 5B757C63699 for ; Tue, 27 Oct 2020 15:44:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 148F82242E for ; Tue, 27 Oct 2020 15:44:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603813451; bh=ZxkpQIgEWIQoiM8qTiWxMoB60zakyUYyXHGwt/vZj9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=pFdwytp1fTrw56pzi8i5IeKHdWXJeCIYHPbVRSv2f76AiQtUjzXNH+1M2WTw/Luw3 Q0F4Ka3bJ4z5mGSrtW/7SaJk4eoce5UJ4X6GKrXk5zW6DoaX9Y1IOte7xpeVl2spZF zKtcJS6chshg+vcKsx52CPCrqdB4427vlQJkgHEc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1801702AbgJ0PnO (ORCPT ); Tue, 27 Oct 2020 11:43:14 -0400 Received: from mail.kernel.org ([198.145.29.99]:53500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1800120AbgJ0PfF (ORCPT ); Tue, 27 Oct 2020 11:35:05 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id ECD6D2225E; Tue, 27 Oct 2020 15:35:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603812904; bh=ZxkpQIgEWIQoiM8qTiWxMoB60zakyUYyXHGwt/vZj9E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qpDa3OK30pERBS8rHaWnJhx6It1eThE3sPsnDJrzd+7U0CgUfO33FYvoXjtp8pYGX JhTifNvK/oFGJafav7YKpoRhELGJVo+O+u11Vwivs6Fm4vuH9Gu0V+2WNTyMXsH4eO ZIpMI13wiSmwm+onPKKPxQnfpSxM4BHtBwVLm5i0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrii Nakryiko , =?UTF-8?q?Toke=20H=C3=B8iland-J=C3=B8rgensen?= , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.9 343/757] bpf: disallow attaching modify_return tracing functions to other BPF programs Date: Tue, 27 Oct 2020 14:49:53 +0100 Message-Id: <20201027135506.657819238@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135450.497324313@linuxfoundation.org> References: <20201027135450.497324313@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: Toke Høiland-Jørgensen [ Upstream commit 1af9270e908cd50a4f5d815c9b6f794c7d57ed07 ] >>From the checks and commit messages for modify_return, it seems it was never the intention that it should be possible to attach a tracing program with expected_attach_type == BPF_MODIFY_RETURN to another BPF program. However, check_attach_modify_return() will only look at the function name, so if the target function starts with "security_", the attach will be allowed even for bpf2bpf attachment. Fix this oversight by also blocking the modification if a target program is supplied. Fixes: 18644cec714a ("bpf: Fix use-after-free in fmod_ret check") Fixes: 6ba43b761c41 ("bpf: Attachment verification for BPF_MODIFY_RETURN") Acked-by: Andrii Nakryiko Signed-off-by: Toke Høiland-Jørgensen Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- kernel/bpf/verifier.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index fba52d9ec8fc4..5b9d2cf06fc6b 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -11046,6 +11046,11 @@ static int check_attach_btf_id(struct bpf_verifier_env *env) } if (prog->expected_attach_type == BPF_MODIFY_RETURN) { + if (tgt_prog) { + verbose(env, "can't modify return codes of BPF programs\n"); + ret = -EINVAL; + goto out; + } ret = check_attach_modify_return(prog, addr); if (ret) verbose(env, "%s() is not modifiable\n", -- 2.25.1