Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp629964rwe; Wed, 24 Aug 2022 06:45:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR47kQ3ll3g/w0c7RqUljoBhPPy6vecLKKuKNQvqV4fMEb0wfUJZLaituFpKHdDnFBOrpiSV X-Received: by 2002:a05:6402:428a:b0:42e:8f7e:1638 with SMTP id g10-20020a056402428a00b0042e8f7e1638mr7723935edc.228.1661348730503; Wed, 24 Aug 2022 06:45:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661348730; cv=none; d=google.com; s=arc-20160816; b=AVpX/LnSuXDNd+OBD41TBBoxPqztJZ6G1479Qe5R91gaBJNIlVFVo778RlxTc46lyA XidS6SChgGaxFVRD/iIj54Ix0pSWGm1Ai110jAl244zJsiMF3N+dz0Nik/yhmnLb/oDV S//VkJWOBbhAD9DONLvf168DlUl4X0VNJQKdXOJlaa9nAyWK+W+EOm5hM+055vXT3UYn Iyv0sVWFaBTRxTOSOeRRczTtJw7cIKTk0EELhhIiFG3xsDCezPg91L2VuhfbUQ4hFXpA n9p357bSM5KVX0m802So8o4Ho9eA3V8N1EStCOiO1rlsC1VkVV7obCAzn3A3sgcDoHne gwJA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=T4/9u8eD7FcgWw8gX8MJJHYFD16U3D9wVzRST8jgEjk=; b=Qdp6ClXEc6N5juw1+jeUWtFcJXu0kSWkQOn/g94YWxwjwlY64pw/wYpeXcE7LXwyX+ 3ywhRJ1WjMkawzar9FIwOkad+emsIadvtpZPPJUnpaBmd4RCjqG1zdu8o1wDLSYDUd9t jZyAbH/HWugvJYoNT1ApmF+AxL64ksRO4Kaba8MX6RcIJxYtYS3Jh1STx5TPikdtjL7s ubt6z2gD0pyRVM35w72yQKOxRA2RFCJIunHqn+kWqWkN2qaz000aYNXAYBopiG7667X4 ALmpRHns1Qm+7Z1jcF5/9iWetlLRm4SvWhX/8dGlUSDQgpK25X1IoqcTbT1z0kujMloi AhzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="YTG/5BYJ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q4-20020a50c344000000b0043c40e2b258si3619765edb.248.2022.08.24.06.45.02; Wed, 24 Aug 2022 06:45:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="YTG/5BYJ"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238595AbiHXNmH (ORCPT + 99 others); Wed, 24 Aug 2022 09:42:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60888 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238217AbiHXNll (ORCPT ); Wed, 24 Aug 2022 09:41:41 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 65AF78036F for ; Wed, 24 Aug 2022 06:41:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661348488; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T4/9u8eD7FcgWw8gX8MJJHYFD16U3D9wVzRST8jgEjk=; b=YTG/5BYJ7TPz3pWjIXftpYgL2gxj+umB5BRuP4YKqkMHI454Dh5qYPEHA7v/m5oNiaqnky qeT+/U65z6Q//L1M/z4ZaC3HRL9neG+kim9uMu7yOaqHW/Cn7eq3TPMnEeRHbJE6iwBhUY mkNXX2X+OeKt3Wekg4k27UyTj7gkLWE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-402-BrHUujMmP3u6lYykwoDL2A-1; Wed, 24 Aug 2022 09:41:27 -0400 X-MC-Unique: BrHUujMmP3u6lYykwoDL2A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0860E38025E7; Wed, 24 Aug 2022 13:41:23 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.192.211]) by smtp.corp.redhat.com (Postfix) with ESMTP id D614918ECC; Wed, 24 Aug 2022 13:41:19 +0000 (UTC) From: Benjamin Tissoires To: Greg KH , Jiri Kosina , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , Kumar Kartikeya Dwivedi , John Fastabend , KP Singh , Shuah Khan , Dave Marchevsky , Joe Stringer , Jonathan Corbet Cc: Tero Kristo , linux-kernel@vger.kernel.org, linux-input@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-doc@vger.kernel.org, Benjamin Tissoires Subject: [PATCH bpf-next v9 06/23] bpf: prepare for more bpf syscall to be used from kernel and user space. Date: Wed, 24 Aug 2022 15:40:36 +0200 Message-Id: <20220824134055.1328882-7-benjamin.tissoires@redhat.com> In-Reply-To: <20220824134055.1328882-1-benjamin.tissoires@redhat.com> References: <20220824134055.1328882-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham 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 Add BPF_MAP_GET_FD_BY_ID and BPF_MAP_DELETE_PROG. Only BPF_MAP_GET_FD_BY_ID needs to be amended to be able to access the bpf pointer either from the userspace or the kernel. Acked-by: Yonghong Song Signed-off-by: Benjamin Tissoires --- no changes in v9 no changes in v8 no changes in v7 changes in v6: - commit description change new in v5 --- kernel/bpf/syscall.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index a4d40d98428a..4e9d4622aef7 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -1437,9 +1437,9 @@ static int map_update_elem(union bpf_attr *attr, bpfptr_t uattr) #define BPF_MAP_DELETE_ELEM_LAST_FIELD key -static int map_delete_elem(union bpf_attr *attr) +static int map_delete_elem(union bpf_attr *attr, bpfptr_t uattr) { - void __user *ukey = u64_to_user_ptr(attr->key); + bpfptr_t ukey = make_bpfptr(attr->key, uattr.is_kernel); int ufd = attr->map_fd; struct bpf_map *map; struct fd f; @@ -1459,7 +1459,7 @@ static int map_delete_elem(union bpf_attr *attr) goto err_put; } - key = __bpf_copy_key(ukey, map->key_size); + key = ___bpf_copy_key(ukey, map->key_size); if (IS_ERR(key)) { err = PTR_ERR(key); goto err_put; @@ -4941,7 +4941,7 @@ static int __sys_bpf(int cmd, bpfptr_t uattr, unsigned int size) err = map_update_elem(&attr, uattr); break; case BPF_MAP_DELETE_ELEM: - err = map_delete_elem(&attr); + err = map_delete_elem(&attr, uattr); break; case BPF_MAP_GET_NEXT_KEY: err = map_get_next_key(&attr); @@ -5073,8 +5073,10 @@ BPF_CALL_3(bpf_sys_bpf, int, cmd, union bpf_attr *, attr, u32, attr_size) { switch (cmd) { case BPF_MAP_CREATE: + case BPF_MAP_DELETE_ELEM: case BPF_MAP_UPDATE_ELEM: case BPF_MAP_FREEZE: + case BPF_MAP_GET_FD_BY_ID: case BPF_PROG_LOAD: case BPF_BTF_LOAD: case BPF_LINK_CREATE: -- 2.36.1