Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp3160720pxb; Tue, 12 Jan 2021 07:46:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJz69aT1vxrUFriM0XkwTPpasaFm51Z1DMcO/GcAqg+25eQfs+Zlrl76xjPJOxzQz4BK7J3D X-Received: by 2002:a05:6402:2d1:: with SMTP id b17mr1081093edx.95.1610466373773; Tue, 12 Jan 2021 07:46:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610466373; cv=none; d=google.com; s=arc-20160816; b=T1DJj+IkGYVgSeUwwJ5h4R85tUJ/OrhD7ca8iaPP0CspvgjoUG6BXg8OTWptS5nfwr zqbfYp5xNk6Yh8VgGgv59d8xWaZjkwJGpCIslSUnzR7JPYi4PR2OOfcReq/6xTbRpUjy uXo8TiQdUMz2FydafRNGr/CcNZGGRZdXOiqu7rk6W3OeFflOjL4isXp9v2yhDSfsNzyo fUBMJrgczQiyucttV5iORyeXZ44AeblRToX8s+j+h+8pTbeQrhq4BM8oyaHZqDLI8/5l RqR/UiVNor66OiUSAtxRdlKBff96x+bk5WyCpQQkbNcGjjGs73vmOi+8ffDPmhiHiZlD oIAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:sender:dkim-signature; bh=k9pbdDmCq+Kt2qJMctj6Pr05hMu+91sEgpkcVDGx9/A=; b=yQo5CFBXsG9rB2IS9he2IDvzXAXpJ3+1+dGhtW83zQ644YhzeaR2LpoIPFJ0oBpxE4 3SWmtnZ85YMDT2rTn3CKrOQiIDHsLheDj5pH+IyZA1yO3fNLt73qe29DZIli/EocqIpm cn+HWuqk/wbqja8Ky+M3WaJvX/uMiGk1AjqzPHlQq12oIZfzP30wdzoOwQZMRoRf4paz Ff0NlQV8xDwgSnTZW9jteACu92hrln3A3XGy+WK+gOyI0Q+4mpFe634S39f/bWrio1cX OVs5yklwCfD4dCIK36HEclENH8U39pYhfxsj0Kx+MyxxhvpSenNvOTKn69eSV5geEbl8 8A/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RjUMTBVU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s13si1540605eds.57.2021.01.12.07.45.50; Tue, 12 Jan 2021 07:46:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RjUMTBVU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404818AbhALPoF (ORCPT + 99 others); Tue, 12 Jan 2021 10:44:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404618AbhALPoD (ORCPT ); Tue, 12 Jan 2021 10:44:03 -0500 Received: from mail-wr1-x449.google.com (mail-wr1-x449.google.com [IPv6:2a00:1450:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2198BC0617A7 for ; Tue, 12 Jan 2021 07:42:51 -0800 (PST) Received: by mail-wr1-x449.google.com with SMTP id 88so1313248wrc.17 for ; Tue, 12 Jan 2021 07:42:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=k9pbdDmCq+Kt2qJMctj6Pr05hMu+91sEgpkcVDGx9/A=; b=RjUMTBVUN4Fgn/2wl75pan+QYPDIsOGv5ef2bH0pTtXNXm5egoOUGlXOcNoKyx+3kT ybZWT/pCmNJZXKb5Aw6N0dN1E2uEKGnn4Ur0PBnzYQFXNmHirs08ZYX2LDQmlvkAaSgb 6zH+ZGDheL3UTPVFiqYML1fKOIRYETReDi7FfSSjP0PxeUbvKB7K5Q3qnA5nmmVE3BhY D4CBzuXRtwnqBtzIojgAeuB6WZZTGdK/o+hAbiFF0lS3L2prMBUCsvgogNV/CedUxVzj Dq7HAUBSGPR5lJGFeYr/pEOPxPpakOi+WlDDNfmOCmBSmTpYtqDRjgokFClGIabgBqe9 uD+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=k9pbdDmCq+Kt2qJMctj6Pr05hMu+91sEgpkcVDGx9/A=; b=cLmccVw1fr+fTo26yiyim4rmYklqQ/fHjhppraS5eooS66oJFYWg8ZoCXq1Yo+jGMV MlV1WCsGq1kOCPedUbycdQlv50Y377uN1UVMjKyNerFOsuhPDM9IQ/MIYEtqqrspleA3 +nT76Ux1GoetW4DUObx+Avu8Bo7AKg1KSfssImSc19V5TBw+t0aAeJxNO/xMg7yp3fc9 NnjQI6maTI4SuT9gpsVT0lUpAMhIuYrar8IpWbAcQsjSdP8m7Is5Qsa8zAK+Rqcfgpt/ KG9YCG9gCPTRVIlvIs54D+hJjHldgiMy8FimqTYCGkuDPut6zX+QpUWk/q4gYtGny6QY qKFA== X-Gm-Message-State: AOAM533FvJ5za4k78x+IPXxNeCAdGMoszX/VKIyq/iXdkTY+8ffQlUvL YGfhwvnuzBEvRdjUfETQjxAZeSHpUalbJQ== Sender: "jackmanb via sendgmr" X-Received: from beeg.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:11db]) (user=jackmanb job=sendgmr) by 2002:a1c:bd43:: with SMTP id n64mr4179187wmf.169.1610466169857; Tue, 12 Jan 2021 07:42:49 -0800 (PST) Date: Tue, 12 Jan 2021 15:42:29 +0000 In-Reply-To: <20210112154235.2192781-1-jackmanb@google.com> Message-Id: <20210112154235.2192781-6-jackmanb@google.com> Mime-Version: 1.0 References: <20210112154235.2192781-1-jackmanb@google.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog Subject: [PATCH bpf-next v6 05/11] bpf: Move BPF_STX reserved field check into BPF_STX verifier code From: Brendan Jackman To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , KP Singh , Florent Revest , linux-kernel@vger.kernel.org, "=?UTF-8?q?Bj=C3=B6rn=20T=C3=B6pel?=" , John Fastabend , Yonghong Song , Brendan Jackman Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I can't find a reason why this code is in resolve_pseudo_ldimm64; since I'll be modifying it in a subsequent commit, tidy it up. Signed-off-by: Brendan Jackman Acked-by: Yonghong Song Acked-by: John Fastabend --- kernel/bpf/verifier.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index d562268c1fd1..48e398667a69 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -9528,6 +9528,12 @@ static int do_check(struct bpf_verifier_env *env) } else if (class == BPF_STX) { enum bpf_reg_type *prev_dst_type, dst_reg_type; + if (((BPF_MODE(insn->code) != BPF_MEM && + BPF_MODE(insn->code) != BPF_ATOMIC) || insn->imm != 0)) { + verbose(env, "BPF_STX uses reserved fields\n"); + return -EINVAL; + } + if (BPF_MODE(insn->code) == BPF_ATOMIC) { err = check_atomic(env, env->insn_idx, insn); if (err) @@ -9940,13 +9946,6 @@ static int resolve_pseudo_ldimm64(struct bpf_verifier_env *env) return -EINVAL; } - if (BPF_CLASS(insn->code) == BPF_STX && - ((BPF_MODE(insn->code) != BPF_MEM && - BPF_MODE(insn->code) != BPF_ATOMIC) || insn->imm != 0)) { - verbose(env, "BPF_STX uses reserved fields\n"); - return -EINVAL; - } - if (insn[0].code == (BPF_LD | BPF_IMM | BPF_DW)) { struct bpf_insn_aux_data *aux; struct bpf_map *map; -- 2.30.0.284.gd98b1dd5eaa7-goog