From nobody Sat Feb 7 15:10:00 2026 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (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 D192D2E091E for ; Mon, 12 Jan 2026 14:59:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768229948; cv=none; b=K+370+lKEvFKaaiKDNxWCzkG75qZPFioxbgxwi8yLaHJJz8GPbjSCrxj7IiauskXVRQbBPXzg1q38tmFhoAR6XwkbtnEDrBqf5NjvWmiGdIUghIQIVJvif4nm/UeAxUlxlf8682KPZrLrZgYu/uSmHMj6WH+ZlCjGJ3Rc4xYS1I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1768229948; c=relaxed/simple; bh=Sd6kjmcaCXlBqUaLAjclh0f3QiFQsnwhx468YsBIWmg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pf4LRLu6X7pqrzINYf4p3vfQLRKZKeJLlGBra9IXUaUPTJb8gu5wIjrlceSasDB38F4OvRmutx9IchYbOypUzlcoGxSmuQtGCj3A5vq7hhdQJo/ZzEaYTkh8SdEIIQakqe4I2s6V4SGyRHBFDrSKIRohlg321ZjnYb2B22AM4iY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=UnjiVaFF; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="UnjiVaFF" 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=1768229939; 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: in-reply-to:in-reply-to:references:references; bh=cDMsVM7/q+LG7mOV7x4BV2sDHWDr164LMBflINOkD7E=; b=UnjiVaFFOn09LuIKaDbn7dZo93lz0NAPEI/TfDPjmieEyQ/V3xPtS7vFi9tLuh/ON9Cbw+ VSvZc4JqTc8cD5hcspSp9TjPGYnWfVbV/6s1h9nEuZLNGkOjQZ1Ugtuhq5KQ4ogYcucJYj shurTFX7QTIQ4dnY3ObY82qPxg2sE7I= From: Leon Hwang To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Christian Brauner , Seth Forshee , Yuichiro Tsuji , Andrey Albershteyn , Leon Hwang , Willem de Bruijn , Jason Xing , Tao Chen , Mykyta Yatsenko , Kumar Kartikeya Dwivedi , Anton Protopopov , Amery Hung , Rong Tao , linux-kernel@vger.kernel.org, linux-api@vger.kernel.org, linux-kselftest@vger.kernel.org, kernel-patches-bot@fb.com Subject: [PATCH bpf-next v5 4/9] bpf: Add syscall common attributes support for prog_load Date: Mon, 12 Jan 2026 22:56:11 +0800 Message-ID: <20260112145616.44195-5-leon.hwang@linux.dev> In-Reply-To: <20260112145616.44195-1-leon.hwang@linux.dev> References: <20260112145616.44195-1-leon.hwang@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" The log buffer of common attributes would be confusing with the one in 'union bpf_attr' for BPF_PROG_LOAD. In order to clarify the usage of these two log buffers, they both can be used for logging if: * They are same, including 'log_buf', 'log_level' and 'log_size'. * One of them is missing, then another one will be used for logging. If they both have 'log_buf' but they are not same totally, return -EUSERS. Signed-off-by: Leon Hwang --- include/linux/bpf_verifier.h | 4 +++- kernel/bpf/log.c | 29 ++++++++++++++++++++++++++--- kernel/bpf/syscall.c | 9 ++++++--- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h index 4c9632c40059..da2d37ca60e7 100644 --- a/include/linux/bpf_verifier.h +++ b/include/linux/bpf_verifier.h @@ -637,9 +637,11 @@ struct bpf_log_attr { u32 log_level; struct bpf_attrs *attrs; u32 offsetof_log_true_size; + struct bpf_attrs *attrs_common; }; =20 -int bpf_prog_load_log_attr_init(struct bpf_log_attr *log_attr, struct bpf_= attrs *attrs); +int bpf_prog_load_log_attr_init(struct bpf_log_attr *log_attr, struct bpf_= attrs *attrs, + struct bpf_attrs *attrs_common); int bpf_log_attr_finalize(struct bpf_log_attr *log_attr, struct bpf_verifi= er_log *log); =20 #define BPF_MAX_SUBPROGS 256 diff --git a/kernel/bpf/log.c b/kernel/bpf/log.c index 457b724c4176..eba60a13e244 100644 --- a/kernel/bpf/log.c +++ b/kernel/bpf/log.c @@ -865,23 +865,41 @@ void print_insn_state(struct bpf_verifier_env *env, c= onst struct bpf_verifier_st } =20 static int bpf_log_attr_init(struct bpf_log_attr *log_attr, struct bpf_att= rs *attrs, u64 log_buf, - u32 log_size, u32 log_level, int offsetof_log_true_size) + u32 log_size, u32 log_level, int offsetof_log_true_size, + struct bpf_attrs *attrs_common) { + const struct bpf_common_attr *common_attr =3D attrs_common ? attrs_common= ->attr : NULL; + memset(log_attr, 0, sizeof(*log_attr)); log_attr->log_buf =3D log_buf; log_attr->log_size =3D log_size; log_attr->log_level =3D log_level; log_attr->attrs =3D attrs; log_attr->offsetof_log_true_size =3D offsetof_log_true_size; + log_attr->attrs_common =3D attrs_common; + + if (log_buf && common_attr && common_attr->log_buf && + (log_buf !=3D common_attr->log_buf || + log_size !=3D common_attr->log_size || + log_level !=3D common_attr->log_level)) + return -EUSERS; + + if (!log_buf && common_attr && common_attr->log_buf) { + log_attr->log_buf =3D common_attr->log_buf; + log_attr->log_size =3D common_attr->log_size; + log_attr->log_level =3D common_attr->log_level; + } + return 0; } =20 -int bpf_prog_load_log_attr_init(struct bpf_log_attr *log_attr, struct bpf_= attrs *attrs) +int bpf_prog_load_log_attr_init(struct bpf_log_attr *log_attr, struct bpf_= attrs *attrs, + struct bpf_attrs *attrs_common) { const union bpf_attr *attr =3D attrs->attr; =20 return bpf_log_attr_init(log_attr, attrs, attr->log_buf, attr->log_size, = attr->log_level, - offsetof(union bpf_attr, log_true_size)); + offsetof(union bpf_attr, log_true_size), attrs_common); } =20 int bpf_log_attr_finalize(struct bpf_log_attr *log_attr, struct bpf_verifi= er_log *log) @@ -901,5 +919,10 @@ int bpf_log_attr_finalize(struct bpf_log_attr *log_att= r, struct bpf_verifier_log copy_to_bpfptr_offset(log_attr->attrs->uattr, off, &log_true_size, si= ze)) err =3D -EFAULT; =20 + off =3D offsetof(struct bpf_common_attr, log_true_size); + if (log_attr->attrs_common && log_attr->attrs_common->size >=3D off + siz= e && + copy_to_bpfptr_offset(log_attr->attrs_common->uattr, off, &log_true_s= ize, size)) + err =3D -EFAULT; + return err; } diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 0b389bc6add8..f369b9ec9d60 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2865,7 +2865,8 @@ static int bpf_prog_mark_insn_arrays_ready(struct bpf= _prog *prog) /* last field in 'union bpf_attr' used by this command */ #define BPF_PROG_LOAD_LAST_FIELD keyring_id =20 -static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 uattr_s= ize) +static int bpf_prog_load(union bpf_attr *attr, bpfptr_t uattr, u32 uattr_s= ize, + struct bpf_attrs *common_attrs) { enum bpf_prog_type type =3D attr->prog_type; struct bpf_prog *prog, *dst_prog =3D NULL; @@ -3085,7 +3086,7 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr= _t uattr, u32 uattr_size) goto free_prog_sec; =20 bpf_attrs_init(&attrs, attr, uattr, uattr_size); - err =3D bpf_prog_load_log_attr_init(&log_attr, &attrs); + err =3D bpf_prog_load_log_attr_init(&log_attr, &attrs, common_attrs); if (err < 0) goto free_used_maps; =20 @@ -6174,6 +6175,7 @@ static int __sys_bpf(enum bpf_cmd cmd, bpfptr_t uattr= , unsigned int size, bpfptr_t uattr_common, unsigned int size_common) { struct bpf_common_attr common_attr; + struct bpf_attrs common_attrs; union bpf_attr attr; int err; =20 @@ -6225,7 +6227,8 @@ static int __sys_bpf(enum bpf_cmd cmd, bpfptr_t uattr= , unsigned int size, err =3D map_freeze(&attr); break; case BPF_PROG_LOAD: - err =3D bpf_prog_load(&attr, uattr, size); + bpf_attrs_init(&common_attrs, &common_attr, uattr_common, size_common); + err =3D bpf_prog_load(&attr, uattr, size, &common_attrs); break; case BPF_OBJ_PIN: err =3D bpf_obj_pin(&attr); --=20 2.52.0