Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp2578099pxb; Mon, 19 Apr 2021 08:49:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJztqpNIJzc9X/PeBPTY+5NI8zrfRtPS+HamGheYVTJoaFiXXHh9DwWVsFgFeajgkF1DXnFl X-Received: by 2002:a17:90a:cc0d:: with SMTP id b13mr25537049pju.219.1618847369548; Mon, 19 Apr 2021 08:49:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618847369; cv=none; d=google.com; s=arc-20160816; b=SEZKh8RvvDbSyc8G9XCKAESL6wsc20PZ4gw6pds1nAEfQjTILbrCmOAgOgeFdoRu40 +lgsacI6OxFGUosF5R3vg1/0HeE5MhZXr83YLJDWZeEkpWq4fJBwsqMuImSvrdtAXVRy FCOovOpuJr/y1mSV4DHsdtmNf8SymjG8ZK/cW8a5QOhDQjcd7j01tw5iX6PNVsoMXklY j2sLCcuSV+upN6UmZXwFqdSmH45p4lMhY9rxVzw1qGlryejzmNZukUKW3LVyffoMZwht 1lADlQl+E2TaB0JuGVuwA9evALA+3/M7aLp7zOxegcV2EiZ4Qq74bbwj2/e7CfaxEfaA 0P+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0mZKtpQcE8qA8lmGPLp9wniuxbhTdFER2+ZhQTp79SY=; b=Jmh/ll7JkpBcH+oZuEX3bGKLOnwjwGyHNbgEWdR5uHCSne+67zYhbaf4UEQEaNgso4 BDLakPesPZsL50/hbka7coX5lMHPxy38Z6fe66kba0XFXZY/gFPBAl9xbxGh+R/kcQBD jOkF9nPRZAw30UyW05YfD+ONtFKKyeAozRNsI+xRDgI7F+qnzs/ZZ2RhEtemYujKPZTs 3IV4aCi4v0Kb4wZvOHcnX2U/Yrcnw0kRRP4J+ZNLhx4cCGfQ9ij2gRSrvKuEksE8kiIj MePWonWfTswXprJLcakBXq+RyLub4tCRzJJ5IXLy/fOfGypD0M/8snCpixsqTHpxJceO HETA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XOF19gPB; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l13si17741533pjm.38.2021.04.19.08.49.17; Mon, 19 Apr 2021 08:49:29 -0700 (PDT) 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=@linuxfoundation.org header.s=korg header.b=XOF19gPB; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243033AbhDSNa3 (ORCPT + 99 others); Mon, 19 Apr 2021 09:30:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:55076 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240446AbhDSNVJ (ORCPT ); Mon, 19 Apr 2021 09:21:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 671EB6113C; Mon, 19 Apr 2021 13:17:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1618838270; bh=qq66I6qbYwlbGwFsEdGhQkCbaAzxhxEKjKBPFvP+p9I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XOF19gPBoTvxHxChDJ4OqU6j63TTTuoMtGDs+5/5fm7d1Lcm5Vy3XuFEZNX9eoOTR Hv8Qj6k+intsZ5m2zNqT35AiyzFHC84Bq89wqOJ0QrdhOLLx84YWQf6yRZmYkqsvLE ttJY6hyjSXXGaLCTQ/S98LAFqOJT1CgsCRyaUv1g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Borkmann , John Fastabend , Alexei Starovoitov Subject: [PATCH 5.10 103/103] bpf: Move sanitize_val_alu out of op switch Date: Mon, 19 Apr 2021 15:06:54 +0200 Message-Id: <20210419130531.318224891@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210419130527.791982064@linuxfoundation.org> References: <20210419130527.791982064@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Daniel Borkmann commit f528819334881fd622fdadeddb3f7edaed8b7c9b upstream. Add a small sanitize_needed() helper function and move sanitize_val_alu() out of the main opcode switch. In upcoming work, we'll move sanitize_ptr_alu() as well out of its opcode switch so this helps to streamline both. Signed-off-by: Daniel Borkmann Reviewed-by: John Fastabend Acked-by: Alexei Starovoitov Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/verifier.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -5417,6 +5417,11 @@ static int sanitize_val_alu(struct bpf_v return update_alu_sanitation_state(aux, BPF_ALU_NON_POINTER, 0); } +static bool sanitize_needed(u8 opcode) +{ + return opcode == BPF_ADD || opcode == BPF_SUB; +} + static int sanitize_ptr_alu(struct bpf_verifier_env *env, struct bpf_insn *insn, const struct bpf_reg_state *ptr_reg, @@ -6389,6 +6394,12 @@ static int adjust_scalar_min_max_vals(st return 0; } + if (sanitize_needed(opcode)) { + ret = sanitize_val_alu(env, insn); + if (ret < 0) + return sanitize_err(env, insn, ret, NULL, NULL); + } + /* Calculate sign/unsigned bounds and tnum for alu32 and alu64 bit ops. * There are two classes of instructions: The first class we track both * alu32 and alu64 sign/unsigned bounds independently this provides the @@ -6405,17 +6416,11 @@ static int adjust_scalar_min_max_vals(st */ switch (opcode) { case BPF_ADD: - ret = sanitize_val_alu(env, insn); - if (ret < 0) - return sanitize_err(env, insn, ret, NULL, NULL); scalar32_min_max_add(dst_reg, &src_reg); scalar_min_max_add(dst_reg, &src_reg); dst_reg->var_off = tnum_add(dst_reg->var_off, src_reg.var_off); break; case BPF_SUB: - ret = sanitize_val_alu(env, insn); - if (ret < 0) - return sanitize_err(env, insn, ret, NULL, NULL); scalar32_min_max_sub(dst_reg, &src_reg); scalar_min_max_sub(dst_reg, &src_reg); dst_reg->var_off = tnum_sub(dst_reg->var_off, src_reg.var_off);