From nobody Sun Feb 8 11:43:28 2026 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 58EDC34D4FB for ; Fri, 23 Jan 2026 03:26:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769138802; cv=none; b=QAA/nAz58HJ89YiL2UgaP0nd3ba7cQ2pLz8L09EUrjdvvII0sHgwKy8z/gARgq3PFxSkuMisPlr2F2EZyiHUcQbDJc/+9Eo+wCqyhyupXxcpZ1hbdP1urQIy2dIQxMIsyLdjWuh7pjJo+vIMaXaCD7aNs7tQI2CvNC1YJBzBJao= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769138802; c=relaxed/simple; bh=USSgFhIgNkJkCa3MhLwDzVL9wdU3Z47qDGqjnKZ+GeQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QeC0IfkPCTFsX6ZyjwQSTKX/8lal6c9PNhfIIzBM5HAQzHq3kCwfp4bRCkVDYw5BvwJZuuxlWReOHMp5jwQEgJ8+lMlKkuA55fmxKjK2JsxoDzhQurYRwoTFEql8tA4cAQcxpOKGTLF5Q13PsYnpq1i6pBrMXUklIxj/esXKxQw= 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=LJ0jBzcU; arc=none smtp.client-ip=91.218.175.185 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="LJ0jBzcU" 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=1769138778; 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=4oNysg7eRr3NvRmo80BWS1H7XtTEokr9/t7DGX+DMqc=; b=LJ0jBzcUnbDsWuiYeK/Gw+Xw3UmsmU3sYL4we9sMddwhse2YXKlcUGwxnm3joRkgHwCAGL lXDNc4NrFFGC+i7BL/fIND9yt8I7KhNWIRR92gq+9ke8UbYFb5P9x9jdxmPK0BxKuL8n0S 52SY1ouZtdJ/UQ09ivF0M21UOD/2YcA= 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 v7 4/9] bpf: Add syscall common attributes support for prog_load Date: Fri, 23 Jan 2026 11:24:40 +0800 Message-ID: <20260123032445.125259-5-leon.hwang@linux.dev> In-Reply-To: <20260123032445.125259-1-leon.hwang@linux.dev> References: <20260123032445.125259-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 -EINVAL. 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 4a0c5ef296b9..7eb024e83d2d 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..c0b816e84384 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 =3D attrs_common ? attrs_common->att= r : 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 && common->log_buf && + (log_buf !=3D common->log_buf || + log_size !=3D common->log_size || + log_level !=3D common->log_level)) + return -EINVAL; + + if (!log_buf && common && common->log_buf) { + log_attr->log_buf =3D common->log_buf; + log_attr->log_size =3D common->log_size; + log_attr->log_level =3D common->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 8468baf545c5..8f3e489667d7 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 *attrs_common) { 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, attrs_common); 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 attr_common; + struct bpf_attrs attrs_common; 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(&attrs_common, &attr_common, uattr_common, size_common); + err =3D bpf_prog_load(&attr, uattr, size, &attrs_common); break; case BPF_OBJ_PIN: err =3D bpf_obj_pin(&attr); --=20 2.52.0