From nobody Tue Jan 27 00:09:32 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 E787C329E4B for ; Mon, 26 Jan 2026 15:15:29 +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=1769440531; cv=none; b=sQIgDp2+LkPl8BCHDVf/AO2UQR5KDK9j7MzzWt4AhgCdMufOlxNYvQDIansuivatyd9f3mHBftAGamyXmI5BykRvwgHfNQKARFLC8zd54stqfsNePL6YCpu/8GSzIb94EH9G6v/9tB59JW1bPGwQl+vCPGzVTHn0rYfaAajZ19Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769440531; c=relaxed/simple; bh=n73GNLF5hUUtTlNZBHjxfVWGz/aHm7xtBCqlxGzf/5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Zq1oiqX28rrMOQQiIevZW55/4ALw4MbXejQ4qL5mzEgnMJ8ZlZQHjYA+m+s/zXyAHZ5RXyPQS2IKxdC8lZp2BArCrmQyZjUvkkNZICOk3z63yToC+vmcplc2+QHo52OrbSxoinrxLQUc1FRSrB6MyEbmYiKuNk0fgcurrMsGOEM= 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=qgpVLBWp; 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="qgpVLBWp" 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=1769440527; 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=bqMAK62FUEdGritvnuOWR/1nXfdD5l2yLQw1KVjWJ84=; b=qgpVLBWpAn9FlwsErx2xWxOlgWnntVZaxKwUBAcn5ewz6OeZPBdGaeNde1gePy6AtWmMYF SLa/x+szc4/rxQv39TDYz1E0NwKjb9YrGjI5wF6VjlYJ0HC5vNMuQZes8d09Y9kuSoU9Gq R39osF5hSXZYOfbS97Pje5KX8DhbThA= 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 v8 4/9] bpf: Add syscall common attributes support for prog_load Date: Mon, 26 Jan 2026 23:14:04 +0800 Message-ID: <20260126151409.52072-5-leon.hwang@linux.dev> In-Reply-To: <20260126151409.52072-1-leon.hwang@linux.dev> References: <20260126151409.52072-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 d422664e00dd..3d1d1181b9b4 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 @@ -6190,6 +6191,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 @@ -6241,7 +6243,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