From nobody Wed Feb 11 12:08:24 2026 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 43F8614900B for ; Sat, 25 Jan 2025 02:18:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737771489; cv=none; b=nikia0NEBNBksUSO7NgxRqTQx2xyd2v4tldHTzoKGrPX6JdBDnUuZTvzhU37cxrpWAqHPSciG1M1Xvod0F5d8osLHxHrf0iBP9GUAZ8iIC1eV734uG7AIbtvBU/ZHtXn9+urtOVhjFZkQMUDEpn7GeHCxhqzdzY3DmFQercT6RQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737771489; c=relaxed/simple; bh=AtSgQqGcoKI6lPQ7U6NaPo/GE657YtZ+2oXd3eGvrYU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=nsdb8XewBLRQ3a6biHL23Og2JxoWXeVX7fbgJc5wJN3UdwFg74SBZ9KxvLZDsqNGcR4xf4xt9a0A8yN5hAputA8/0XDfJJdB9LZSq1k26HzXS/T2TFMowrC9wdQcbUmtkTDKlU+I5natk0sDYQj/rSvGXUUPgYJ5AM/mzNl0Ieo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--yepeilin.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=c8JXMHZV; arc=none smtp.client-ip=209.85.216.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--yepeilin.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="c8JXMHZV" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2ef35de8901so5014205a91.3 for ; Fri, 24 Jan 2025 18:18:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1737771487; x=1738376287; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=SAhOVvwp95DURlQLkWceP8oOZonYxW56RQWdJ+tqdYo=; b=c8JXMHZVF8P8G2b46/1T1WbhsYJC4K0QrjjmSIYgA2VXL4fXw+wjZS6fxjMD4z0Qa4 5EE4ycNrs1Ke0DPxoMpTnolyhBirSKG8nDnF8dg4FLHLqD+XLWq+LUlrhFrOjBvOyYuF trIeWgljc6YHdVp4spdn8AVAZ/S2cY3ACEVXh6lh0NINgSt5dTXh7dombmWaiFlMXvn2 u2P/vUF+6Im47c6Yaxf3bW23Vt7KwRv6S/HW3hNfulNFyoatf+umlY8fD9VuNsEwL1nQ 6VsM0/E+mcKzSdoMtRrE3XnHIby2y5D2/8DgROUfyWWVOk4TKo+tT2uGc1iUGbxFRtWz EEAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737771487; x=1738376287; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=SAhOVvwp95DURlQLkWceP8oOZonYxW56RQWdJ+tqdYo=; b=dV9frHWXHtYuH/EYq3zND0+yflBpTEzoY7+MQ19lWsdGu4tmaZfSUJZhF/ZFFxk+nF hAc5MSTs41X6HH7XG9/7Xr7iXovc3eke1h18CskzXpXIlKu5MToQ8kegx8cm1bjdyX3g Sbl7cBk65kdMFNigdFfKsVbf7XQe9skXE4g3bxLzWa4aADbkRNddNqwQo0xHTLyuPcO8 4VdvXcD2F4ASyNcT3zbZryJFTm0sfsb7wjDxdWyvBcI/wJVULG05CeTO4EvgGuA423UN Jp4+U6SJCmKW7+8MKzb7Ai+jsDUhBc9Qzi8TdAAoeRpUFqRVajDG6EetPkDgg/xMlzSJ GboA== X-Forwarded-Encrypted: i=1; AJvYcCVQpOj+ZC+ZiSvGsakSUO7ZCvTfB23bGVXqNXSZ4TDHfxHCJfTMhq5G7A+DLiXF+GVLkgGQq3EupLhxf3M=@vger.kernel.org X-Gm-Message-State: AOJu0Yw/PFmsmvYyEy5DLapQy1mvNra0+/2HjP1/PBM7PBu59f5uMfIl nH47rOyBrPc6juel/vbSjEgSg9JyBLk4lOiDm3alM6mdaPL2vYqs2XyH4Y9eike4i273UwYWJXW 1DFAgviua4Q== X-Google-Smtp-Source: AGHT+IH+1cbrPKWyykDgl/vF7cElMEjsc9SSUcFXj1Np6Z8pLDvoFHDe47yUm55K1xK5bhBJYeqphCuyAJpw0w== X-Received: from pfbbx20.prod.google.com ([2002:a05:6a00:4294:b0:729:14f9:2f50]) (user=yepeilin job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a00:2e24:b0:728:8c17:127d with SMTP id d2e1a72fcca58-72daf948568mr52769436b3a.8.1737771487369; Fri, 24 Jan 2025 18:18:07 -0800 (PST) Date: Sat, 25 Jan 2025 02:17:50 +0000 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.48.1.262.g85cc9f2d1e-goog Message-ID: Subject: [PATCH bpf-next v1 1/8] bpf/verifier: Factor out atomic_ptr_type_ok() From: Peilin Ye To: bpf@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Peilin Ye , bpf@ietf.org, Xu Kuohai , Eduard Zingerman , David Vernet , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Jonathan Corbet , "Paul E. McKenney" , Puranjay Mohan , Catalin Marinas , Will Deacon , Quentin Monnet , Mykola Lysenko , Shuah Khan , Josh Don , Barret Rhoden , Neel Natu , Benjamin Segall , linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Factor out atomic_ptr_type_ok() as a helper function to be used later. Signed-off-by: Peilin Ye --- kernel/bpf/verifier.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 9971c03adfd5..0935b72fe716 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -6116,6 +6116,26 @@ static bool is_arena_reg(struct bpf_verifier_env *en= v, int regno) return reg->type =3D=3D PTR_TO_ARENA; } =20 +/* Return false if @regno contains a pointer whose type isn't supported for + * atomic instruction @insn. + */ +static bool atomic_ptr_type_ok(struct bpf_verifier_env *env, int regno, + struct bpf_insn *insn) +{ + if (is_ctx_reg(env, regno)) + return false; + if (is_pkt_reg(env, regno)) + return false; + if (is_flow_key_reg(env, regno)) + return false; + if (is_sk_reg(env, regno)) + return false; + if (is_arena_reg(env, regno)) + return bpf_jit_supports_insn(insn, true); + + return true; +} + static u32 *reg2btf_ids[__BPF_REG_TYPE_MAX] =3D { #ifdef CONFIG_NET [PTR_TO_SOCKET] =3D &btf_sock_ids[BTF_SOCK_TYPE_SOCK], @@ -7572,11 +7592,7 @@ static int check_atomic(struct bpf_verifier_env *env= , int insn_idx, struct bpf_i return -EACCES; } =20 - if (is_ctx_reg(env, insn->dst_reg) || - is_pkt_reg(env, insn->dst_reg) || - is_flow_key_reg(env, insn->dst_reg) || - is_sk_reg(env, insn->dst_reg) || - (is_arena_reg(env, insn->dst_reg) && !bpf_jit_supports_insn(insn, tru= e))) { + if (!atomic_ptr_type_ok(env, insn->dst_reg, insn)) { verbose(env, "BPF_ATOMIC stores into R%d %s is not allowed\n", insn->dst_reg, reg_type_str(env, reg_state(env, insn->dst_reg)->type)); --=20 2.48.1.262.g85cc9f2d1e-goog