Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp110544iof; Sun, 5 Jun 2022 22:42:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy7uazOUKOJeQT7xFOOqshuVj1wqzax3DiN7keDm6gWabbLbG1Qr4525/QWGHBNaQ2eX12y X-Received: by 2002:a63:5464:0:b0:3c1:4930:fbd5 with SMTP id e36-20020a635464000000b003c14930fbd5mr19284316pgm.94.1654494135974; Sun, 05 Jun 2022 22:42:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654494135; cv=none; d=google.com; s=arc-20160816; b=U6JH4hJWFg6Pr2NgXaWScPoZXHnCFNdkQ5nrlzzeE0DuAQ8OWLY+kYVVpvSTbib60G 9e0wWqIJ0IlER3XlV3shfkTbQexcGdyr15I0TqOZc9CprVhTPwYVoeN7ZmHv4jXGUcpy lp7nOKmXJM7NjZBjR0DQ1LLhOlcJ12ZCyLBIYGvBQnCZBYjY0AdOaUEH3pUOsfQy3h+s pmsZTdlW4vlsf4LPDbxUyIXzpW5zsqNQqrTr+AE6eFyo4P76UdNMUCFYg473D3FVmUaB LTKX5twNlV2YmvEzb10Zhr58pnmNvNxN5JlegJCNelhpvy803cO5/3o2Zu0G8grtq6Qf Zeog== 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=+zK8u0xE0FiPevc/UlfHTTygzzppMbMXEB2d58gLWcw=; b=Ii7KxEqS+egylh+xYS8kgfpfAnBhd8l/DpzhwuhR8Anl9hOlMbbCVlbZU79O6wPRtT twPCMPywkXo9Q22vuLPgMmAC9Dn+arKKE03iH/Ciry0cgtlFLUz2BWWO6XIBiwM8Nbz9 zXl0MgE6zKjVckASjs7ukw6W9Zx7KRvVzE3iO9zbEJ7567iWKLHZ7uCsdFOeY2CWOFPF mbU7iHHFBhleyGbG0a2iNpSbWkl7sIlf6lUeOswg2kUjzc+Xcqg3tuv82CHh1NZnb3vB Pg7PxuYVWSmpCp1ODMG9Y0z4y+OQdb8EdwPjZRYHddyJ3P3h1wBYk0Ie8arbpn/9ksWV iyWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GFqMcWw0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id h10-20020a170902f2ca00b001631214cc97si1632262plc.350.2022.06.05.22.42.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:42:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GFqMcWw0; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4E1A621D483; Sun, 5 Jun 2022 21:33:12 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243710AbiFCSSw (ORCPT + 99 others); Fri, 3 Jun 2022 14:18:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347900AbiFCSG1 (ORCPT ); Fri, 3 Jun 2022 14:06:27 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CED905D5F8; Fri, 3 Jun 2022 10:59:25 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F3D09B82189; Fri, 3 Jun 2022 17:59:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BAA8C385B8; Fri, 3 Jun 2022 17:58:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654279139; bh=jylEjt/kulbTS7GurMgB9K2xH/8vWaxgWIIDnWNp0L8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GFqMcWw0VZtKRFds+RBdbUt+Ny7HnlVKzxlunQ1Hqx3ZJyeXfjvkiqzl1WYHYrXYA 2GPzqus93laXOFvQE094xrDxwd74Rks2JGPcgYIEXeNCsm/ECAkAbrXWTmsGIDtv3X XUDXGzwbRi/BHu8PMXHPO/6rpf9d2wSbLTFclxkI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kumar Kartikeya Dwivedi , Alexei Starovoitov Subject: [PATCH 5.18 65/67] bpf: Reject writes for PTR_TO_MAP_KEY in check_helper_mem_access Date: Fri, 3 Jun 2022 19:44:06 +0200 Message-Id: <20220603173822.586723850@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603173820.731531504@linuxfoundation.org> References: <20220603173820.731531504@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kumar Kartikeya Dwivedi commit 7b3552d3f9f6897851fc453b5131a967167e43c2 upstream. It is not permitted to write to PTR_TO_MAP_KEY, but the current code in check_helper_mem_access would allow for it, reject this case as well, as helpers taking ARG_PTR_TO_UNINIT_MEM also take PTR_TO_MAP_KEY. Fixes: 69c087ba6225 ("bpf: Add bpf_for_each_map_elem() helper") Signed-off-by: Kumar Kartikeya Dwivedi Link: https://lore.kernel.org/r/20220319080827.73251-4-memxor@gmail.com Signed-off-by: Alexei Starovoitov Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/verifier.c | 5 +++++ 1 file changed, 5 insertions(+) --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -4861,6 +4861,11 @@ static int check_helper_mem_access(struc return check_packet_access(env, regno, reg->off, access_size, zero_size_allowed); case PTR_TO_MAP_KEY: + if (meta && meta->raw_mode) { + verbose(env, "R%d cannot write into %s\n", regno, + reg_type_str(env, reg->type)); + return -EACCES; + } return check_mem_region_access(env, regno, reg->off, access_size, reg->map_ptr->key_size, false); case PTR_TO_MAP_VALUE: