Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp599092pxu; Thu, 3 Dec 2020 08:08:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJy8DRdrM2M1PFL87aG06+B2BK2FvENRBRO5KmMepvBRABbINmWp7XC3kyC6Cz/+XLkCjJ3b X-Received: by 2002:adf:ea45:: with SMTP id j5mr4583685wrn.171.1607011709691; Thu, 03 Dec 2020 08:08:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607011709; cv=none; d=google.com; s=arc-20160816; b=FD5bzg4fa0RpT9QmPwBqYZxOvTLfsxiIsH6xz3MG2Lh2wDR1aR+hUzs4ePMn8kAtzr S9btsGDSExppZEzZMyPtrK4PqCzpOaYduf8sbH9iEIJyyGjo30mJWl06v8gEpD4vJlHI GDsL1G7xDmrO5nELkjbW+bnIoImWDV5zXNBwbE4Aach21kGGflqs0OKOAQc6FhaVcMcp wTQ/Vq+OdWCAkfFjOAsMiGXY0KAMcf58k/VvjHndHtHaYM42YEH0Sg1khaCIRhQT00cT QA3ntvPm9WigjxhBlndxcx8D8lhCdNXxSPhm7fFDkXPAKGd2K6JUEMY511R/WH1A7WLt Frng== 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=P/yq/QQWbpB7r4QFh7S+AKecPYKN/ajhsuXzhalk5DU=; b=gNOf3xECwCIsTrgmGJTWyU8Y3yoExR6aDdNw3+m77qCTDjtCM3OqE17puouc4gvT7S dtnUzmmHkT9BMk4fsYaVt68wCAC5i8kijwmjytnf9j8eVaVjgkBhnJ+i/w5NOioEC8Ub A80AHUuAB/HXJOAMpuX5pAcItMQCY59Fdb/r0ra1H5cnNXvIyO1ceiU8UTQsWOWtzNY1 ZtN0ZTt1Is8QPWt7nKeuYYSmVZArOHrzrbUUuy03aviZTpUz+iJ6Vu3mGDAWIRZ71o11 ByE4daSIZPly0LOtra3kw+4cPKeNFOkgVYjj5QmIgC3/InPJtQB2lLHyZZPFkbNxsDKU 5ncA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=nk3c1Pr1; 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 j9si1277626edl.351.2020.12.03.08.08.05; Thu, 03 Dec 2020 08:08:29 -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=nk3c1Pr1; 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 S2436728AbgLCQEl (ORCPT + 99 others); Thu, 3 Dec 2020 11:04:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436587AbgLCQEj (ORCPT ); Thu, 3 Dec 2020 11:04:39 -0500 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CDFF3C08E862 for ; Thu, 3 Dec 2020 08:03:23 -0800 (PST) Received: by mail-wr1-x44a.google.com with SMTP id w17so1409961wrl.8 for ; Thu, 03 Dec 2020 08:03:23 -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=P/yq/QQWbpB7r4QFh7S+AKecPYKN/ajhsuXzhalk5DU=; b=nk3c1Pr1/+i7APpWeoY7LSgu1pCCyRq/vSUN8hqvQ9hfqnXht8rHs3eImodgT8++kR o3/W9PA0EcGW72ltEJH8mfk+Au8TLr3PhqrgHgpNAjn5L5yBRJ5VGOpqgd7Q93RxlA95 vUaJ0Z2JKPqK+k1LB5oxvyK3AINNAIRnIj+Z57ZtDnL80qrJGghy/iVzEFXfWTWOdQLz BPX+Pc0M9TKUBYT27UFffn2lI8iKVlDyYXBmo2ILwgM73fL9WuiKgBbqK3rbon0xk9KY kdKy6fdni/99+aivkAfVis+LeCHg+/Tj+X1u+IqMNsmMc6SzpDpJ2VZQzE5HoSjlivvm qjKw== 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=P/yq/QQWbpB7r4QFh7S+AKecPYKN/ajhsuXzhalk5DU=; b=WBif/jmuthk1dgd9D8q88VKH4UtDTQ1ej5wrHoCig0euPfsClyKEVkFt18SxMg/mwH +jFRvvhSlUGvu0JXPHeW2ZyfAhPp73JyT9EDPBcjhFdgNI/SusW6CeFiX6gYDV76esDr VsGle8ux/DXFhmPeNr7HtKEkqkB9r+YIkahGr5Xu1+NMtizSMKvqTY/4H2PVX93fvCNa iry6xukFfZle9jd40PHJ659gef3uHRMehu5bpQ8tCW9ebHr9Lbm+gz0mPhNQAeA3vrZZ cK1hOtlbBMl7qM/Rh/9FXE1p5PeNeNhWJxeLDSEHlGLZfVYm8M2If4TKiqu5j406cbDA 9NfA== X-Gm-Message-State: AOAM532K/FOON0DVi+URN23qdBKNoiZUI+gCnV9B6HUYWDuv1ArWyO4H gotfOXlZzzhA+xXgF7VupjlRz09i8yAnKA== 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:a7b:c5c6:: with SMTP id n6mr3982703wmk.131.1607011402494; Thu, 03 Dec 2020 08:03:22 -0800 (PST) Date: Thu, 3 Dec 2020 16:02:37 +0000 In-Reply-To: <20201203160245.1014867-1-jackmanb@google.com> Message-Id: <20201203160245.1014867-7-jackmanb@google.com> Mime-Version: 1.0 References: <20201203160245.1014867-1-jackmanb@google.com> X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH bpf-next v3 06/14] 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. Change-Id: I3410469270f4889a3af67612bd6c2e7979ab4da1 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