Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp272761lqb; Thu, 14 Mar 2024 10:49:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUhHWFmm/rD0fLy7Cg9VtcNylvU53Z9H0GyFUboY/yiuAmJu3JJzhl05a/kcde0GgDEdnl8oUV8d/4wUoTQLOpO2mi9JClk2fpkQEcyWA== X-Google-Smtp-Source: AGHT+IF3TgOLT6wd4FlL1ZJav5qEx5R84bFIhRzaMP1gEOel4dV8FOAbjkl/Nsgt3yUkXPu5+cLj X-Received: by 2002:a05:6359:4117:b0:17e:6a5b:75ba with SMTP id kh23-20020a056359411700b0017e6a5b75bamr2713986rwc.21.1710438587516; Thu, 14 Mar 2024 10:49:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710438587; cv=pass; d=google.com; s=arc-20160816; b=n6nXk0jzzcwN1M8rGoIwqN75kPoRCsL1DmltymnMSHOoXp+FJpaHxkiSM4AKwJOaEg 4h4rUZq9rj51HMQNzbXCqlQM+5OT/mgIz/pBM1zqJoWQSXiv5OlSNqKvpNC5lFvAW0Ls kROZl3prnFMD8kld+iTyvrQKIBgVdwK2Jbi9knA8r/HfGwNC0wwKOuiX4NisgLDhYA2F giDZ1eofsZAec908wIiMIkZDNWKeeJRL0szCxM18syqn93RmO4r0nqAIvIvMjlIaLpHx 97u2BsuGuHHLgSCSzg09YD/tKVy1XtGPHsn/ShrYAtaN/fSF3gA3k5bvDU6U+ilhA809 Re/g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=6sTrFM/7u+qguknxAtmm7g0jvXeK16BxRSJMHNHbRBI=; fh=N/4voPnXVBFrvJJgmsapYBaK+Y4uHZjqHCnqiJlB0OQ=; b=LkSSrpQEkmtcXsez9AAhOCu54VBnJpro0x7ZkTVRyYkrpT8seD2TXvgyN4cmD/jCsX o9D6soFdIJm5LObNk+3GozRwfGwj6Nzs3pHQ7QUG/kO417EXqLnV5QUkIAnCwRLMlLSJ 4wL5IbZ9PVZTw7ZynpjgRdE1P/SGuCj2yV5ADDpEAAGDUkNkX9ry11NmBm61bzHQkr98 orameW3jdqyLp3LdH34XO4DQpAddR1Y6rel7dm4EdGuKxhFy4GKUlmz28aXPlPc6y1Yk TZEqw4eDxzfwRAAMCvZWmu2wOWOwZIj56iwAAvKojeUNgeRPLLsezWoSfzfkJt+14hr6 x7pQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UQ0dkRqX; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-103635-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103635-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id h2-20020a635302000000b005dc891520f0si973830pgb.272.2024.03.14.10.49.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 10:49:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-103635-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=UQ0dkRqX; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-103635-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-103635-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 2EF2228382E for ; Thu, 14 Mar 2024 17:49:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 424AA74BF4; Thu, 14 Mar 2024 17:49:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UQ0dkRqX" Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 CF87841C6D; Thu, 14 Mar 2024 17:49:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710438579; cv=none; b=XPslvN4Fn+SLgTBGtC++/+mXE/WfELJnYLL/KiO4f0xkWOZhDEVRCRDLxBtZwd1miyXeUEfgNSZw8or1qstpMw4y7+1q/YF5dClVOJT+gCz0rE0VGkNzUAAq+3dFAuvUvTNiLChSl4GTyv5HQ6pFtE9phOPDvi7zn1yR/1/p7nE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710438579; c=relaxed/simple; bh=mM+v1kmQ3/Nx0Xb+0QIWcpLvojmmSfnlNtCYXhBw2WA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Cq8ryi8Hg+22FoMmKB10RhSBAjTSXIfI+Y+Ux/Kik+ekboNDcmf83GDH/15FT79KmH/4NtDRRv6N+itgGIqoI2+XkTkIlPSM9LeM9gp/N8aLKiC+yBGNrtrFJYPy2FCNplNHsctfJruhC5IYzLJhUg+VtGy5Ptkd+kHv2XMpwPw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UQ0dkRqX; arc=none smtp.client-ip=209.85.128.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-413feb4d7b4so859075e9.3; Thu, 14 Mar 2024 10:49:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710438576; x=1711043376; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=6sTrFM/7u+qguknxAtmm7g0jvXeK16BxRSJMHNHbRBI=; b=UQ0dkRqXxVUtrBFJ1J6W21YGErNR2Gz43drOmf9JTE73LGDfIOC2AyTogtj1kR8OkZ qcgCH01Fyuxm71bt2/8p2XmM+hbP03EG4PZk+BYhk0NmXkEqSwsq7tsHPCLzZbY6Nbun S7P+fJwtyizzn3U9DzZkH2M/6Yua80Jg/lTS5+uNNH4Lekb4KCK2B7ZiujfaBfmmzA0m /N3VS56v4MmHDxA1NgVU4iBE/IrIu23bkgD17LSbGirhDOE/lT075m8GRjGhUhTMr2EF VhtGp/+3J66N9Vej4cxx0ng6pNkTXQI6CVVulzq1/2OpJUwxpaZg2hx72191G8tehwnO JdAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710438576; x=1711043376; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=6sTrFM/7u+qguknxAtmm7g0jvXeK16BxRSJMHNHbRBI=; b=auCepSmUJ+CbKsOuY/qzaw0/5G5hVPaCs3w8hS1szEtL3w5ZlayK3wUMqmk0x6EV5D uP9GmKJiCg7Khz10ZMfa6JwFeulyEdSKhA7GTPQUlZDzs3yXU5/+S5xPij9jMoYBV/0H tH6VSChCFmRFtetqPekjEQJK0/+K7u29Yyp2LqxRRd/P4wme/a/mH4jA0pcZOYMLQGdG gegF8Lq7sb24QzIhnl5IUmtRNN2M4VapF6XrjBbqLPkpODaR9ejs/k/KS5ICkuvTzgUD FxM6eouEjVU5h8eZi0fMGC/wQhAhR6k4CWWQCCqhrH2Nvf1sEXLh+oeK/+0hqlxD2O+6 ULxQ== X-Forwarded-Encrypted: i=1; AJvYcCW0J8kq3uE1G4Pdb5sU32c9bBX6jzeJ3mcjI9X63yH9ctJjkOkL7FSP/DSRE6yjFckKCXPlnX6N2qD4IbbxcGJNfoBGdBiIigNXzfVJtJHCql1t7TxMfvKu1QZfCxhD9wl3 X-Gm-Message-State: AOJu0YzasF3g/nq9DzDuhr2Y8l574RHEQgtHZiKIFaBRnIj/I8zgoqp/ u9FNWY+lYXLPC+zwrDBnrPmgapjm/fO4S5uriV0sS3r3xa4nRYhD X-Received: by 2002:a05:600c:358a:b0:413:1872:6ad7 with SMTP id p10-20020a05600c358a00b0041318726ad7mr576116wmq.29.1710438575901; Thu, 14 Mar 2024 10:49:35 -0700 (PDT) Received: from localhost (54-240-197-231.amazon.com. [54.240.197.231]) by smtp.gmail.com with ESMTPSA id i13-20020a05600c354d00b00413e6465413sm6199472wmq.27.2024.03.14.10.49.35 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Mar 2024 10:49:35 -0700 (PDT) From: Puranjay Mohan To: 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 , Kumar Kartikeya Dwivedi , bpf@vger.kernel.org, linux-kernel@vger.kernel.org Cc: puranjay12@gmail.com Subject: [PATCH bpf] bpf: Temporarily disable atomic operations in BPF arena Date: Thu, 14 Mar 2024 17:49:31 +0000 Message-Id: <20240314174931.98702-1-puranjay12@gmail.com> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Currently, the x86 JIT handling PROBE_MEM32 tagged accesses is not equipped to handle atomic accesses into PTR_TO_ARENA, as no PROBE_MEM32 tagging is performed and no handling is enabled for them. This will lead to unsafety as the offset into arena will dereferenced directly without turning it into a base + offset access into the arena region. Since the changes to the x86 JIT will be fairly involved, for now, temporarily disallow use of PTR_TO_ARENA as the destination operand for atomics until support is added to the JIT backend. Fixes: 2fe99eb0ccf2 ("bpf: Add x86-64 JIT support for PROBE_MEM32 pseudo instructions.") Reported-by: Kumar Kartikeya Dwivedi Signed-off-by: Puranjay Mohan Acked-by: Kumar Kartikeya Dwivedi --- kernel/bpf/verifier.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 63749ad5ac6b..1dd3b99d1bb9 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -5682,6 +5682,13 @@ static bool is_flow_key_reg(struct bpf_verifier_env *env, int regno) return reg->type == PTR_TO_FLOW_KEYS; } +static bool is_arena_reg(struct bpf_verifier_env *env, int regno) +{ + const struct bpf_reg_state *reg = reg_state(env, regno); + + return reg->type == PTR_TO_ARENA; +} + static u32 *reg2btf_ids[__BPF_REG_TYPE_MAX] = { #ifdef CONFIG_NET [PTR_TO_SOCKET] = &btf_sock_ids[BTF_SOCK_TYPE_SOCK], @@ -7019,7 +7026,8 @@ static int check_atomic(struct bpf_verifier_env *env, int insn_idx, struct bpf_i 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_sk_reg(env, insn->dst_reg) || + is_arena_reg(env, insn->dst_reg)) { 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)); -- 2.40.1