Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1568249pxu; Fri, 27 Nov 2020 10:00:53 -0800 (PST) X-Google-Smtp-Source: ABdhPJzQha+ZTe6D4UjksY5GxOTZSyuD96joEExMyc0sObW66jJfDv1XI3KDn6j1MOsERnZXOvUO X-Received: by 2002:a17:906:a182:: with SMTP id s2mr8830395ejy.249.1606500053449; Fri, 27 Nov 2020 10:00:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606500053; cv=none; d=google.com; s=arc-20160816; b=hrKtkA0KGIiv/97wYRaq80ZFXvRrK6aNakVvuWGIRdn/+n54wfISJXI8w/kv9VQD5y SlCBJ5wLVM0wfFWIwIvNPRi8Ym+EVdfpQIdelpQz3K1Fb00NlRpOYCb0aVGyRnz3g1iG p31XLZhdQ6w2t5htzYOMU9jtonlTD1mjtRC36pffqC4a1P55XT06jhcNdC6YHnJL9ffM 0QZwImDgofBJ4iXY32euGJi/xnIHaf4S8ZKsF+OezAXTil6vD9OpS/FjIP0IHHcrzsnE ooGx/Y9mQBXmxi0xWpzPm62Nl/gXn8IilyC5ypGsSnBcU2bPk5yEJLrPWyDKv0EuuOZ+ nfgg== 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=zbpGVgr8tNKDgthNqGrhordV2MhrhuH8IzD17QyNfdQ=; b=lhKpvI5Je1tZZPccInsfHBqOkdovjSVGV0DULNxVfE+GBHpClIBa7XELO9AO1zZzdn o3KgmqOy/y8QefoF9hpv9M/rIOyokWx/vCG28eptxSCDey8Lu9J5Tc6of6OnfKrb+Pki qZAZhVP886zq9S3ln+xDtl3uk1OUB3yRRfcZfnnwBywCU6KnKQTdvzeCt0ngKD8MIEo5 4rhestAenKs+doaKOAubyeaiAEnswJqMy62XubMgVqc5KeAiGOEv0fEHyholjGj1npl7 VufVb9XOIYg360+R71Sh7Qt9niF8kZfj4ICk6l2AgXu6TJuhUWQNxSIaWv4HYKF3qrmj 9Qpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Cp+XgwyL; 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 bs1si6771768edb.320.2020.11.27.10.00.30; Fri, 27 Nov 2020 10:00:53 -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=Cp+XgwyL; 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 S1732926AbgK0R6G (ORCPT + 99 others); Fri, 27 Nov 2020 12:58:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730985AbgK0R6C (ORCPT ); Fri, 27 Nov 2020 12:58:02 -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 775D0C0613D1 for ; Fri, 27 Nov 2020 09:58:02 -0800 (PST) Received: by mail-wr1-x449.google.com with SMTP id z6so2047747wrl.7 for ; Fri, 27 Nov 2020 09:58:02 -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=zbpGVgr8tNKDgthNqGrhordV2MhrhuH8IzD17QyNfdQ=; b=Cp+XgwyL/DQSmzZ1190ENwLk/KCOR1R/9fKDea7XXBnGJQKHwda/BkhBDsSBnP6+Gz b0dV/egvQo3YKiLXVOcjivnl4oW4rtubUUAnheZSrnGy08WoTHfHe4B0G1iIavdKtzaO Xo1E5o0R9ww4ZMpvHa+mpZDFY8crVQQAD+JGbhLm/AozjZQHti6pYWMLMaqpJy/K4/0q LEm/it1Oz0OnPFnXDh1TUDq9LHmrGOxl+7g1fauQ3CXxn+KSp7Po46OJwYlc2g6yE6Az EV++zDfV7Z13674e7QYD64BC67as9iD2sUwY6j+4YON+7sryWrC68j9MDqe8qXV6xri+ MyTw== 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=zbpGVgr8tNKDgthNqGrhordV2MhrhuH8IzD17QyNfdQ=; b=ejhQ6Iwg0T50p9zVh+qauuT6dF0Npe5thRBIw74KjLkKHycjGUxa1kSMlexHlyQA+V JB7vp+4zJI1pCdOa5pdvIJVYnnu6YrmTpvl+sGIfLj5VrmovAbVa6Dl2kCrjkTOFsT7w rsd1EsboptToWCGbBgLRRAW8HSjzred5NfrpFyzlCxton9LBOih0umhfe/lChzzZCY5W 8GQ0TLP9fWVcsvC3G5m2xUkuq/2e+dLryjgUF1GyabFmPAHLvN7ahsvISrcvwourbGbN k/FpOtjIj0MlkhOfIVlpKTlmyqUWCGdJa4kypnTZByUFHUwHTjBiXpUqh3tiOO3sivs3 QoHw== X-Gm-Message-State: AOAM5324gjFVYpJOhj5Nw1L4Q8OPyz/KWzsdR3O7f3zqXA4BmfpnblE3 41GxuZkr58OLvvYSQPx2GzBNocPmBmLZ8w== 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:791a:: with SMTP id l26mr1857691wme.1.1606499880798; Fri, 27 Nov 2020 09:58:00 -0800 (PST) Date: Fri, 27 Nov 2020 17:57:31 +0000 In-Reply-To: <20201127175738.1085417-1-jackmanb@google.com> Message-Id: <20201127175738.1085417-7-jackmanb@google.com> Mime-Version: 1.0 References: <20201127175738.1085417-1-jackmanb@google.com> X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH v2 bpf-next 06/13] bpf: Move BPF_STX reserved field check into BPF_STX verifier code From: Brendan Jackman To: bpf@vger.kernel.org Cc: Alexei Starovoitov , Yonghong Song , Daniel Borkmann , KP Singh , Florent Revest , linux-kernel@vger.kernel.org, Jann Horn , 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 --- 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 1947da617b03..e8b41ccdfb90 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -9501,6 +9501,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) @@ -9910,13 +9916,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.29.2.454.gaff20da3a2-goog