Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp274522pxx; Wed, 28 Oct 2020 04:44:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxrbGPAwOaovJc93ujfoEkFXX55VMljTF3YcgMVtjNj4LkSV1BCls/rs/iCj1yYZNj7VGJf X-Received: by 2002:a17:906:b084:: with SMTP id x4mr7357328ejy.374.1603885487871; Wed, 28 Oct 2020 04:44:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603885487; cv=none; d=google.com; s=arc-20160816; b=p8F3Fafgt/EnNeklzhVIi4ZauecV2smHLUds9ZDwuI+2DkkZ5yhC6pECaUjA0twtm2 HfxUnY4cPgDzzBqfpQLMOi2Pzlt9blXnbTLJa9Xkgfu8N1v/peCBmjsyye2VIaHk6Ao6 Pw1H7fypCHqti/ko904Brb4fD90Tim0cfFYr9frb2f214Lg3kyV5vWUBLfGm5ycwCGPF sUt0vkIeeuFjKSnJxzVEUqqYYDninqboaeEo8nkLXJmCGrU3Fohs2Ie8HXc4hnQbmNn2 Ye5GkGfX0mWFmmsFLz6ZzoPj3l+nuMKPp7ERCB0jkUC4PY1XLYenOYkaFqgX236CjzjC Emgw== 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=Gf8K1ZuTQ3HN6ZbdjLwU3Z5PS1XBOmdC74E0hK6ESEI=; b=f6IBA3C8+gJkp/rbapqXRapcIFwA98El4mJnmy49QBxQx2jDIzuYVVSU3TyQDQUMoG 9h/n+7ZtV0XLMPAumIQ2EYZAS+52deqETipBCmyBOYkzDGDzymopBisnQJVvZ5/1yI1T qqy8Eg2cmg96YhNOhYNBgFEwyp4mvnj/w2awLbNYNEeH1eVh8K2T568yIi2JgmC/uohu SwKNnlweJk6HZMJUTKKWbqdUXGWNmPcv3/r3IrvO+AhK3+7SVmyPUPkEKxezMFF1QzYV JHSNNYV9+eP6VQyDQMOCRNYmwYcDEq7xbR0ERRP2W725ZIjKfOxkYO+9pmTHlWBvJsMu VfPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="y10WjN/Q"; 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=fail (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 s16si2897729edy.300.2020.10.28.04.44.24; Wed, 28 Oct 2020 04:44: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=@kernel.org header.s=default header.b="y10WjN/Q"; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1794357AbgJ0PLZ (ORCPT + 99 others); Tue, 27 Oct 2020 11:11:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:36454 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1789443AbgJ0PCR (ORCPT ); Tue, 27 Oct 2020 11:02:17 -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 30B4C22264; Tue, 27 Oct 2020 15:02:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603810936; bh=a+59OxeN9xs6Fxpc/rKpyBqirWjAQKAuC7Piklj+mMI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=y10WjN/QJc9CKkST7qkp99GnZdWKFFd5Eel81m/j7vclHas2ZxzoXJ+g6wJpI/XNv 0WVdzvmV2lb7gtjqko0/hBs3iCW3Oid41Tz6jfu8K9SBMtQ372aHEsWrx1c9xw79WC hor601pvNS1hpgE061noyzXYAAQsaUUvTQuqWk90= 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.8 285/633] bpf: disallow attaching modify_return tracing functions to other BPF programs Date: Tue, 27 Oct 2020 14:50:28 +0100 Message-Id: <20201027135536.051765016@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135522.655719020@linuxfoundation.org> References: <20201027135522.655719020@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 89b07db146763..c953dfbbaa6a9 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -10862,6 +10862,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