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 EEA6E17727; Mon, 27 May 2024 19:30:08 +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=1716838209; cv=none; b=fK35uMxNQwEMKtyiLpAlUL8ltU6xVVRATUmsDqMTWYMyJFxMe24WhqJL9eZj6es+3frFRlIJFMFsxA/9+FFvvQsyyd36/N8SB/iQwlSbYyMLFOIJG43HP29g8O3eTHJUqZOcGo9esPQKWtCVJWTFVNugqqrXtb2yWmgSRhVVuoU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716838209; c=relaxed/simple; bh=LFApEpaM5wrImS7VdPG7ICjiLGq+bpfRE9mSPq+KWhM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oMKOzw6cAvkXyyc7l4pX/HGVH+4TbNqvCWiK112oniso4gh50VBDBFYwE/wtIsDD9VH9MPsHTC/QJostrBcM7Kx6LQr2JFuZimOvBTY/nULAxNrZ5BDhOUY7x2RY5+T0mbleWQobzKtU2FbsdoM3v52HoN4V0x5BjSrWlnhK/Ys= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=wAcwvxGp; 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="wAcwvxGp" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E9BAC2BBFC; Mon, 27 May 2024 19:30:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1716838208; bh=LFApEpaM5wrImS7VdPG7ICjiLGq+bpfRE9mSPq+KWhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wAcwvxGpI00XGjt6F6OyctSuYvSxqEn5DykGJIOrIDhm0nkbBxL9z4max/SoOHYon liKn5aFShGmh25ZotlcvTtp/ZZQrDOeOO+kRi8lbN0XXJrz60isX5TwlsSu6rpZ3rY Ko4wvQqnhmrAStRIQMU3+ahAF5jEqQoxd8KzoiD4= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+838346b979830606c854@syzkaller.appspotmail.com, Stanislav Fomichev , Eduard Zingerman , Martin KaFai Lau , Sasha Levin Subject: [PATCH 6.8 266/493] bpf: Add BPF_PROG_TYPE_CGROUP_SKB attach type enforcement in BPF_LINK_CREATE Date: Mon, 27 May 2024 20:54:28 +0200 Message-ID: <20240527185638.990240481@linuxfoundation.org> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240527185626.546110716@linuxfoundation.org> References: <20240527185626.546110716@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.8-stable review patch. If anyone has any objections, please let me know. ------------------ From: Stanislav Fomichev [ Upstream commit 543576ec15b17c0c93301ac8297333c7b6e84ac7 ] bpf_prog_attach uses attach_type_to_prog_type to enforce proper attach type for BPF_PROG_TYPE_CGROUP_SKB. link_create uses bpf_prog_get and relies on bpf_prog_attach_check_attach_type to properly verify prog_type <> attach_type association. Add missing attach_type enforcement for the link_create case. Otherwise, it's currently possible to attach cgroup_skb prog types to other cgroup hooks. Fixes: af6eea57437a ("bpf: Implement bpf_link-based cgroup BPF program attachment") Link: https://lore.kernel.org/bpf/0000000000004792a90615a1dde0@google.com/ Reported-by: syzbot+838346b979830606c854@syzkaller.appspotmail.com Signed-off-by: Stanislav Fomichev Acked-by: Eduard Zingerman Link: https://lore.kernel.org/r/20240426231621.2716876-2-sdf@google.com Signed-off-by: Martin KaFai Lau Signed-off-by: Sasha Levin --- kernel/bpf/syscall.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 0f90b6b27430d..1860ba343726d 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -3852,6 +3852,11 @@ static int bpf_prog_attach_check_attach_type(const struct bpf_prog *prog, * check permissions at attach time. */ return -EPERM; + + ptype = attach_type_to_prog_type(attach_type); + if (prog->type != ptype) + return -EINVAL; + return prog->enforce_expected_attach_type && prog->expected_attach_type != attach_type ? -EINVAL : 0; -- 2.43.0