From nobody Sun Feb 8 11:26:41 2026 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (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 83ABA2580FB for ; Tue, 6 Jan 2026 17:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767718835; cv=none; b=FTBTUhR+6GCFqE+Ndth7vTV8CV1X+XT5Bf9TgO4sng4Vad8Xe1oY2wYa+8w1SBuvfc3uAP4t4BYDEihDWxx/Z01+WHRT+b5Ut6AHCZ/t1YL557V43ElTPteGBjVBqjIDye4gpuRjahtQQqTgo8/VlG82EwU9IgrtdJMyYZpYo2k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767718835; c=relaxed/simple; bh=hc5NWGN0r9aDg0436s6gyQhJpYTeqZRW/K8Um66wE6I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G0yAbvjdNCz+HLCvTgoFG6w2vOYwezks2GemzUQWyvWZg6YrNQ2Y9fqOleYhZ2Wt83+DubqA3/Q4V7oAWapmkzCChKlIVMvK25Zs9zYm79WBcmkCZ5oh8v41NURCIOlaiIhyUj0DaldDjj7Y5TTh/jqEbGWaoLRZc8SS0XAkrA8= 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=WY4+sPgA; arc=none smtp.client-ip=91.218.175.177 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="WY4+sPgA" 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=1767718828; 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=iRP7dSPyiBjJ0689O8KZb3Eqq91g9ONGcIKtAwQLB2U=; b=WY4+sPgAdrjDWagvz+sa7RCHbCjg7It92+XrImNj73TMpn7kinRtU9jZLHK0qwOZ+Jy9y+ IT7y+MJgqz4WdF+6F2AxKqVr1TGGa8lRXtmWkR4DlkIQgr+UXmDoMxID6JNhW70NNyrweJ rkGpoZkWbuSKkwccDByQ+Sz5EmpztP4= From: Leon Hwang To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Christian Brauner , Oleg Nesterov , Leon Hwang , Seth Forshee , Yuichiro Tsuji , Andrey Albershteyn , Willem de Bruijn , Jason Xing , Paul Chaignon , 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 v4 4/9] bpf: Add common attr support for prog_load Date: Wed, 7 Jan 2026 00:59:02 +0800 Message-ID: <20260106165907.53631-5-leon.hwang@linux.dev> In-Reply-To: <20260106165907.53631-1-leon.hwang@linux.dev> References: <20260106165907.53631-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 --- kernel/bpf/syscall.c | 51 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 3 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 1739601fb7bd..ad565f569a4f 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -6160,14 +6160,55 @@ static int prog_assoc_struct_ops(union bpf_attr *at= tr) return ret; } =20 -static int copy_prog_load_log_true_size(union bpf_attr *attr, bpfptr_t uat= tr, unsigned int size) +static int check_log_attrs(u64 log_buf, u32 log_size, u32 log_level, + struct bpf_common_attr *common_attrs) +{ + if (log_buf && common_attrs->log_buf && (log_buf !=3D common_attrs->log_b= uf || + log_size !=3D common_attrs->log_size || + log_level !=3D common_attrs->log_level)) + return -EUSERS; + + return 0; +} + +static int check_prog_load_log_attrs(union bpf_attr *attr, struct bpf_comm= on_attr *common_attrs) +{ + int err; + + err =3D check_log_attrs(attr->log_buf, attr->log_size, attr->log_level, c= ommon_attrs); + if (err) + return err; + + if (!attr->log_buf && common_attrs->log_buf) { + attr->log_buf =3D common_attrs->log_buf; + attr->log_size =3D common_attrs->log_size; + attr->log_level =3D common_attrs->log_level; + } + + return 0; +} + +static int copy_common_attr_log_true_size(bpfptr_t uattr, unsigned int siz= e, u32 *log_true_size) +{ + if (size >=3D offsetofend(struct bpf_common_attr, log_true_size) && + copy_to_bpfptr_offset(uattr, offsetof(struct bpf_common_attr, log_tru= e_size), + log_true_size, sizeof(*log_true_size))) + return -EFAULT; + + return 0; +} + +static int copy_prog_load_log_true_size(union bpf_attr *attr, bpfptr_t uat= tr, unsigned int size, + struct bpf_common_attr *common_attrs, bpfptr_t uattr_common, + unsigned int size_common) { if (size >=3D offsetofend(union bpf_attr, log_true_size) && copy_to_bpfptr_offset(uattr, offsetof(union bpf_attr, log_true_size), &attr->log_true_size, sizeof(attr->log_true_size))) return -EFAULT; =20 - return 0; + return copy_common_attr_log_true_size(uattr_common, size_common, + &attr->log_true_size); } =20 static int __sys_bpf(enum bpf_cmd cmd, bpfptr_t uattr, unsigned int size, @@ -6225,9 +6266,13 @@ static int __sys_bpf(enum bpf_cmd cmd, bpfptr_t uatt= r, unsigned int size, err =3D map_freeze(&attr); break; case BPF_PROG_LOAD: + err =3D check_prog_load_log_attrs(&attr, &common_attrs); + if (err) + break; attr.log_true_size =3D 0; err =3D bpf_prog_load(&attr, uattr); - ret =3D copy_prog_load_log_true_size(&attr, uattr, size); + ret =3D copy_prog_load_log_true_size(&attr, uattr, size, &common_attrs, = uattr_common, + size_common); err =3D ret ? ret : err; break; case BPF_OBJ_PIN: --=20 2.52.0