Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4327866pxj; Tue, 8 Jun 2021 11:36:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzG9SoXy+uhr89Vi9/r/fI2NSXioD8dJ7GcYIlGh17o3GZzLZbDX2F308eCTfHzfK8T3gmc X-Received: by 2002:a17:907:1117:: with SMTP id qu23mr24981473ejb.71.1623177388040; Tue, 08 Jun 2021 11:36:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623177388; cv=none; d=google.com; s=arc-20160816; b=tCVZYRSQ+1/KGcYUq8o9/L5V3wlLgFNm7oGX/ktTEvYzP+UuTZQ5nyWjfwfLAql2zD 8ZDCAAYrn6NxbB3b6Q0JSvThka5Xkmly7Eb9YTuoIdX+hxwvLpazVVcg4HVo1RWSs8Mj qaeFoeuB3AkemQxWHLIG6mNgzBxH75No464Kpm5HFtpXck+A+kpr+dAQKFDQRx1lNBlW xLkIdksBW2mhye2Gf6+G8XIW9p3ssX0w+vHKzpJR12a1r+wZzN/5mzXyNjGl/EwaX2dM Ga+zX4kzdUyPqfYjy9MOx0hYmHVNPh0GPJPwD+TIWE7UAAGIIfIrZKWapoD+Q5DaO7Vr lgFg== 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=Vdc3VOBkMAvEg/1CE8xWzuvak5K8yCseQnR/mKiQGqU=; b=G9d1y8lParUL6QeVCEJHrnoYFSf6XiuKc7/znrXYameVj5eXoai0xuplkr3YbAMTMW +XvqfSHodlwyw+uQ433Y2Z3q0+/duuZqtrR/jr2pI43wzN0+iVXYLfzIW4APxMwKw2eE qO+WW+0vlO1USt/CgfYbJ6WwfbhaMiX6tLGEfFHBNi/2Bvcs/GU0PBP79cIucCQ3ZN3j 7MpcSfmC8+m8YAvgdV8tjyoBxlLdqxuA7Y43xSVNeA4Jmkti1ClHQtrGD8yLqcKICldc VDX5denlmi/hKsVl5nV5zM/CbF41GAC1UAQ+dfSKTUbMKxYFVZL+kvVsqAOdwMJCbJim t4Xw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=PWnacTYo; 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 c10si414979edn.209.2021.06.08.11.36.04; Tue, 08 Jun 2021 11:36:28 -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=PWnacTYo; 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 S232640AbhFHSfa (ORCPT + 99 others); Tue, 8 Jun 2021 14:35:30 -0400 Received: from mail.kernel.org ([198.145.29.99]:56838 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234283AbhFHSdi (ORCPT ); Tue, 8 Jun 2021 14:33:38 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id D184661406; Tue, 8 Jun 2021 18:31:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1623177088; bh=T+Var+PucczUrS60FLmKd5lWrz4sRsLv8bN2RNHC/gY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PWnacTYoNNToQIjGbcaX5Y13uv4Fi0FrZe3MwA/szl14vSYhhEuyMnTOObwROd4jC Db8Hy7RgRFQbPRopHwh41xII7y86CLqo+HTwkH2Gy+7YrexprlMbknTlqgFFlY6gzm Z5r4IfObBur9evN67xPqCad2ARPRLEpgI4umix24= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Daniel Borkmann , John Fastabend , Alexei Starovoitov , Frank van der Linden Subject: [PATCH 4.14 28/47] bpf: Move off_reg into sanitize_ptr_alu Date: Tue, 8 Jun 2021 20:27:11 +0200 Message-Id: <20210608175931.401585891@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210608175930.477274100@linuxfoundation.org> References: <20210608175930.477274100@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 6f55b2f2a1178856c19bbce2f71449926e731914 upstream. Small refactor to drag off_reg into sanitize_ptr_alu(), so we later on can use off_reg for generalizing some of the checks for all pointer types. Signed-off-by: Daniel Borkmann Reviewed-by: John Fastabend Acked-by: Alexei Starovoitov [fllinden@amazon.com: fix minor contextual conflict for 4.14] Signed-off-by: Frank van der Linden Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/verifier.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2094,11 +2094,12 @@ static int sanitize_val_alu(struct bpf_v static int sanitize_ptr_alu(struct bpf_verifier_env *env, struct bpf_insn *insn, const struct bpf_reg_state *ptr_reg, - struct bpf_reg_state *dst_reg, - bool off_is_neg) + const struct bpf_reg_state *off_reg, + struct bpf_reg_state *dst_reg) { struct bpf_verifier_state *vstate = env->cur_state; struct bpf_insn_aux_data *aux = cur_aux(env); + bool off_is_neg = off_reg->smin_value < 0; bool ptr_is_dst_reg = ptr_reg == dst_reg; u8 opcode = BPF_OP(insn->code); u32 alu_state, alu_limit; @@ -2224,7 +2225,7 @@ static int adjust_ptr_min_max_vals(struc switch (opcode) { case BPF_ADD: - ret = sanitize_ptr_alu(env, insn, ptr_reg, dst_reg, smin_val < 0); + ret = sanitize_ptr_alu(env, insn, ptr_reg, off_reg, dst_reg); if (ret < 0) { verbose("R%d tried to add from different maps, paths, or prohibited types\n", dst); return ret; @@ -2279,7 +2280,7 @@ static int adjust_ptr_min_max_vals(struc } break; case BPF_SUB: - ret = sanitize_ptr_alu(env, insn, ptr_reg, dst_reg, smin_val < 0); + ret = sanitize_ptr_alu(env, insn, ptr_reg, off_reg, dst_reg); if (ret < 0) { verbose("R%d tried to sub from different maps, paths, or prohibited types\n", dst); return ret;