Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp1136029lqt; Sat, 20 Apr 2024 02:11:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWoSYemKhXKGnHy1SvxTsFLE3zvBvLixNMoN82NsWQzBUd947CjV1DLUhgqnrjXHzfzbaYg71XNpUV15KTy+JnJlArqznf17pEAcCywvQ== X-Google-Smtp-Source: AGHT+IE8iAT4gpV1K2lf60CDEzRVnMJknbhBeMmHVC8GHEaiSwQHg4CcGo3LiL89IZLRBNaLmnTh X-Received: by 2002:a05:620a:810:b0:78f:19f7:ad9c with SMTP id s16-20020a05620a081000b0078f19f7ad9cmr4816899qks.54.1713604281801; Sat, 20 Apr 2024 02:11:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713604281; cv=pass; d=google.com; s=arc-20160816; b=VWffERYS1ttW1sY7XDgrOsj60bpalzJmrXxFYyT0efaHktyFSLBznCbW1LcKVwcyZR wa0bCT60PwRYKtSVAwYq0rrjypJM4sp604D5/LMHiQ+l9KC5ydX4OkVqmQAWV3EFbf9h ISV3ckmcv1hJmddOEZjCmgCpibDy+0Tv9mt3RuLwZ6mOhMO38udCsdVFBC1E+m2Rh643 eV60MPHEBfDXfoWpP0Xjircto38bCfLVTvnzEUdsH+ttgGLpO9kSGqy6dqsLlNLhkBdM aArDGjHrr6+FMgGWq/PgI2a4qMobBL+F2f2q9lU97lUiwTaLDlPREvmgFKcafsmZlTd+ HFSw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=Y6ATlAos7hka+7iOl4GtKuu5uB9uyxRmO/ZYSiS5W7g=; fh=Cxwo/A+C89tjOzVq8R/o/DH+l+P6Lpt8VwbqwppZI0Y=; b=GJSiEQkLdi0aBbSQ0+Z1CGLy0kqgYWQ/igoc3pGyFRSiq/ISvNxC0YhoLh9zXzk00b GiChHmnn/HyBLQTwISS5+uaYp8bGyzvKdsjLT2JxBeH2ZLcPECf3tzl2X7I5GWdh7lC1 HHPv8FFBbVT3cgWv7N1i2Qq1C4z/rzLKWL8z/E/0chjX7vr38YV9PNHhKaBZ2ZZOKqZY Y+HiFdIz14Zvvlk2zKMamnBXX8SQQK4Rev2Jd6oEuz/K8wzYOIc8nelSHTqCLsIcxYwG sw4mjW9WTjVt3tXUX+MUuHLUjVg2sKbjCRYiaJeSNzinNws5y0j4ejEH0O7oUOjZ3S6A MICQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UqRJuXeu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-152190-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152190-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id pj16-20020a05620a1d9000b00789ed541240si5599789qkn.330.2024.04.20.02.11.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Apr 2024 02:11:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-152190-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=UqRJuXeu; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-152190-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-152190-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8775B1C212D7 for ; Sat, 20 Apr 2024 09:11:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3F8253D96D; Sat, 20 Apr 2024 09:09:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UqRJuXeu" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5F8163CF74; Sat, 20 Apr 2024 09:09:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713604190; cv=none; b=YbjoKqbiF31BVdXtda8Z7sXCbumdR3CBbrdOUOZxWqxtpZmX1fcykmyEGdlu801fJm5YoIH5K2IADVPVd9kaU1h/7AeLjPNiX7ySR7HcteWxwhVfKwsYE+IeI0zOFg/oKHr9USpUwozsJDxOq5g3LhSSKzhKbvugkPnCvlwyFDI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713604190; c=relaxed/simple; bh=sqBLxwMs8NHUzEqz1nVFEPGoIGPCN7UMcScC2uJ1VVE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=T941IuA8dOgUT0tR0CqWtISa8lnR6RrA8RWIcQCxqGfjgSjQbQAtorNwsDd5Bta+/ofVF5bSDjj0mfDDNfMdkt6KeZ/kydtDwZvQU3TTVdBwEKQQ5PdxbAS4F/bUsYnGwE1q1KlhuxRHL7KfVDXLQ5JzBCAyc5ovX/7bJSBcM4A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UqRJuXeu; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82062C32783; Sat, 20 Apr 2024 09:09:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713604189; bh=sqBLxwMs8NHUzEqz1nVFEPGoIGPCN7UMcScC2uJ1VVE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=UqRJuXeulSmosSNdJqhrhtQLaJ0+o5DCYSEupHTu97VMOVrFyv/fxg6L6XkxwCJqq JVCybv6ZJSmEr8avl5CoYXQSOWU8yAC5O7fHStKxRyadnLBfh0z5msIry14uiPDM31 UWmPdA9DdSTbijZZhwMrdxwLjvkPRm15r3AHGZtVnDZlnywmV21gACvNLG2scYLtEo cxVy9xCyyrqphk0T2Pc35IRn5agNFGscZLCxl4Pdtagj+opRlkVMRp5Imf5mUJbf78 h9DlFgeNOH85SLQSA9qazEG1Ls3FKPO0hNbA5coy2TiN2+e59Cw7i25HK8GkdFl7F9 kqlUzYoqnHshQ== From: Benjamin Tissoires Date: Sat, 20 Apr 2024 11:09:07 +0200 Subject: [PATCH bpf-next v2 07/16] bpf: verifier: bail out if the argument is not a map Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240420-bpf_wq-v2-7-6c986a5a741f@kernel.org> References: <20240420-bpf_wq-v2-0-6c986a5a741f@kernel.org> In-Reply-To: <20240420-bpf_wq-v2-0-6c986a5a741f@kernel.org> To: 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 , Mykola Lysenko , Shuah Khan Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Benjamin Tissoires X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=ed25519-sha256; t=1713604159; l=942; i=bentiss@kernel.org; s=20230215; h=from:subject:message-id; bh=sqBLxwMs8NHUzEqz1nVFEPGoIGPCN7UMcScC2uJ1VVE=; b=zxCBhZfexHvnKwW7ytj7Kj8p2XCvrvWGvnwGLrOkwXY2giKQ7jz3/8B9ywwDBQAi6HKm5ancw 4BSlCxZb8RzCfdkqxely4D14eAGXdMHVRqhwsJhgTP2x2fWf03UXwlj X-Developer-Key: i=bentiss@kernel.org; a=ed25519; pk=7D1DyAVh6ajCkuUTudt/chMuXWIJHlv2qCsRkIizvFw= When a kfunc is declared with a KF_ARG_PTR_TO_MAP, we should have reg->map_ptr set to a non NULL value, otherwise, that means that the underlying type is not a map. Signed-off-by: Benjamin Tissoires --- new in v2 --- kernel/bpf/verifier.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index deaf2e1ab690..b95fd63864f1 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -11720,6 +11720,11 @@ static int check_kfunc_args(struct bpf_verifier_env *env, struct bpf_kfunc_call_ case KF_ARG_PTR_TO_NULL: continue; case KF_ARG_PTR_TO_MAP: + if (!reg->map_ptr) { + verbose(env, "pointer in R%d isn't map pointer\n", regno); + return -EINVAL; + } + fallthrough; case KF_ARG_PTR_TO_ALLOC_BTF_ID: case KF_ARG_PTR_TO_BTF_ID: if (!is_kfunc_trusted_args(meta) && !is_kfunc_rcu(meta)) -- 2.44.0