Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp403894pxj; Thu, 20 May 2021 12:02:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuY+o9+dkGJYlWo2+nI/mzpwqjSWGHzZmdkkP0pW8l1JMkGcHuKe2wnqtbCMyf1E8fKSLc X-Received: by 2002:a05:6602:3427:: with SMTP id n39mr7351790ioz.157.1621537320048; Thu, 20 May 2021 12:02:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621537320; cv=none; d=google.com; s=arc-20160816; b=NGtH1Q6ZEGHN01ieSwwZyLugew2tPs5hEq4DZ/D1d0KdpcMoXVUOxn3zhbDi4T3NtD GbOMvrFjwQk/Igo9vSBen7O7D8fkgDsMUIci35znRXPyyOf0Lwk7BF5MHUhpbWj15cD5 7om34nD/XuGFxRhUra7F7o1Q5ej1m7bohZcDLEWap+gZxvN9K+F6dXu3oEm0aPAWnteU TUjUeEVC9xdkJ8uwfKDr/ieHY3Z/Zgpa8I1maNd9hnaxbmJlyhhOsrn1Rl2ClcSUnqlK rph/990pWEDNCaCkDewYtW/Nbk0XZbUFCJiKXN0d4R1QG0asA2gtUdPUaId8Qn4JaM5t BdHQ== 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=TWYMEDvksES+ziz5Sy6tM8qL7h9FN+ytWi+v7y5V8NY=; b=rMsE1J3UsaH79RI5dXs4D3UNmQe9Rq5bnbGQcHQXqIaNXyW4MO4OHhO3kGCuCQRFml UWt1z1zRcwMpFh26+tBenehPSJbiMzgZWJ5fF3ImKkCIHg2m0wQqYp5wFa/XmzI/RMgy K35uq6v5Bbij+6xZ6P0Znr4IaolnZiB6V1JOzlAaoJ9qje2p4b8nW4liMxuRV9pJwJ1V JintoPs/H4nQI46eLoZHMW2bRkMiUpCpe1Kor0icMAZNeeHoy48K82yK7icRpYAwzy7x 174hWijhU5nP5/qXTP8cCNQYyXKoqbGyHA0xMb0mqfvZb+RuK/8xcEQlVlfGU2b5KZOe HLaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=uwmiPT2m; 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 o10si3273481ilc.147.2021.05.20.12.01.46; Thu, 20 May 2021 12:02:00 -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=uwmiPT2m; 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 S236750AbhETK2I (ORCPT + 99 others); Thu, 20 May 2021 06:28:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:47740 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236473AbhETKPU (ORCPT ); Thu, 20 May 2021 06:15:20 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id F335A6198C; Thu, 20 May 2021 09:45:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503932; bh=beTbDepfJp+gV3uCFBN0fe35WAaiIPXY1D7wJK7dTI4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uwmiPT2mqQu7OA/m8dpi6/Zu3AVD9l4mmcWLbKEZgRxI00866Mi3cJ69yCW0+aj9M +W6Z6icd7EqWeTlAtoVrqfMoCDpzui+h0L9UEqyGkNQ9Z0aJY3+hutwqolL0aqv93Q eYBB/Io+RQ/IZIvq3VFLs4iUq32/3KoH6RSAOTfI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg Kroah-Hartman , Samuel Mendoza-Jonas , Frank van der Linden , Ethan Chen , Yonghong Song Subject: [PATCH 4.14 004/323] bpf: Fix backport of "bpf: restrict unknown scalars of mixed signed bounds for unprivileged" Date: Thu, 20 May 2021 11:18:16 +0200 Message-Id: <20210520092120.276176727@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092120.115153432@linuxfoundation.org> References: <20210520092120.115153432@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: Samuel Mendoza-Jonas The 4.14 backport of 9d7eceede ("bpf: restrict unknown scalars of mixed signed bounds for unprivileged") adds the PTR_TO_MAP_VALUE check to the wrong location in adjust_ptr_min_max_vals(), most likely because 4.14 doesn't include the commit that updates the if-statement to a switch-statement (aad2eeaf4 "bpf: Simplify ptr_min_max_vals adjustment"). Move the check to the proper location in adjust_ptr_min_max_vals(). Fixes: 17efa65350c5a ("bpf: restrict unknown scalars of mixed signed bounds for unprivileged") Signed-off-by: Samuel Mendoza-Jonas Reviewed-by: Frank van der Linden Reviewed-by: Ethan Chen Acked-by: Yonghong Song Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/verifier.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2204,6 +2204,13 @@ static int adjust_ptr_min_max_vals(struc dst); return -EACCES; } + if (ptr_reg->type == PTR_TO_MAP_VALUE) { + if (!env->allow_ptr_leaks && !known && (smin_val < 0) != (smax_val < 0)) { + verbose("R%d has unknown scalar with mixed signed bounds, pointer arithmetic with it prohibited for !root\n", + off_reg == dst_reg ? dst : src); + return -EACCES; + } + } /* In case of 'scalar += pointer', dst_reg inherits pointer type and id. * The id may be overwritten later if we create a new variable offset. @@ -2349,13 +2356,6 @@ static int adjust_ptr_min_max_vals(struc verbose("R%d bitwise operator %s on pointer prohibited\n", dst, bpf_alu_string[opcode >> 4]); return -EACCES; - case PTR_TO_MAP_VALUE: - if (!env->allow_ptr_leaks && !known && (smin_val < 0) != (smax_val < 0)) { - verbose("R%d has unknown scalar with mixed signed bounds, pointer arithmetic with it prohibited for !root\n", - off_reg == dst_reg ? dst : src); - return -EACCES; - } - /* fall-through */ default: /* other operators (e.g. MUL,LSH) produce non-pointer results */ if (!env->allow_ptr_leaks)