Received: by 2002:ac0:da4c:0:0:0:0:0 with SMTP id a12csp687663imi; Thu, 21 Jul 2022 09:02:33 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vhs2mDOB1HO3fqqqDJLrJSKNSj2667T0gNJAVAvwFag+Gh74xw9uIpNz9699DKhMGzmBx4 X-Received: by 2002:a17:907:7617:b0:72b:49fe:fdf7 with SMTP id jx23-20020a170907761700b0072b49fefdf7mr43128155ejc.25.1658419353222; Thu, 21 Jul 2022 09:02:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658419353; cv=none; d=google.com; s=arc-20160816; b=HzmlCP5HFduXGOcsYVAVR2jgIHn84voeUAg2t4yOXy991Jw0jUsuhrcgSMUc1CwUT9 hsh25UwQe+VQV8ZAYfUKfP20FdCsUWIIcNKtB760p+12fXc0skYMCi5g1kjaj6WCphHl vYHlxO3DMUz7Ri5JSz7NhnoVRqRGcNWQ+ip30RKqQrHQ01blSpvP3H1um9NDAGNLw0Jo KF3OXyQWCEZxscbaDh55HyBMI3Wg7qnuIfC0tDoVjizrhRrHXJfi4lXxa2cIkWAP3DsC alQ6KYmo2Jrni8cU/eQUtts1RHl0zh0Qm9tv03DxoMfD/+MVLuI3jDAijrT4Lkg+dmpr CH2w== 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=q1ugzeeQImQSGGFdeXfOpKhPDeYLIbJhcbUeYAyYDFI=; b=lxjd7frAlC6qvT7CHr1/dcoQrcLlXmGgH0em19uXFILV4cFu3Faq+u23MOgXEfxsmX g2Re8GjBNOQAoN+2+S1woGxjmJvwL9Dy753VZr8FXC27KuN/tpmHwjZmidmLP+99y9KM +iLPhGm5Yq+emjhV1xeNPZ7Kl9O2zLruK8Pz68e0AN/STbNKC5RgXY75cCoDnj//Vf8w oDshIa1aEer4il4QWfBQpd5K0TuILawejl+kALrmqmviVUDkr8yXwsf16yW3G/xVy8RB QFw+idcak4fRjAbzY4g5IL/vT5SoaSE+cVXOe2FVlIpDkGVugXV+zTLRQLhstRymotdB wYvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="XOKGlJ0/"; 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 t10-20020a17090605ca00b0072b1cf39434si2755499ejt.961.2022.07.21.09.02.06; Thu, 21 Jul 2022 09:02:33 -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="XOKGlJ0/"; 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 S232752AbiGUPig (ORCPT + 99 others); Thu, 21 Jul 2022 11:38:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232095AbiGUPhz (ORCPT ); Thu, 21 Jul 2022 11:37:55 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DE3DB88CC5 for ; Thu, 21 Jul 2022 08:37:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1658417828; 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=q1ugzeeQImQSGGFdeXfOpKhPDeYLIbJhcbUeYAyYDFI=; b=XOKGlJ0/Kxc+vcNXMBrjb+wG871xSjuTCHzwkWCjFH0qThv1LGwPbWYgz5HyaJy0iLV+no lvoiM1fKVPUJ2TatESfGYkycqUPhe1cUxwsWDSOUahmPw/9TqUVPNjtFGtM02CpmZ6EsSc iqpkaHQHRLBke1MbnsWNmy15xcKSu5c= 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-627-sr70ccOfNYSgI9Vj21KGzg-1; Thu, 21 Jul 2022 11:36:57 -0400 X-MC-Unique: sr70ccOfNYSgI9Vj21KGzg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id ACFC02804067; Thu, 21 Jul 2022 15:36:55 +0000 (UTC) Received: from plouf.redhat.com (unknown [10.39.194.200]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5DDA32166B26; Thu, 21 Jul 2022 15:36:52 +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 v7 07/24] bpf: prepare for more bpf syscall to be used from kernel and user space. Date: Thu, 21 Jul 2022 17:36:08 +0200 Message-Id: <20220721153625.1282007-8-benjamin.tissoires@redhat.com> In-Reply-To: <20220721153625.1282007-1-benjamin.tissoires@redhat.com> References: <20220721153625.1282007-1-benjamin.tissoires@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE 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 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 83c7136c5788..776c7a37c433 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; @@ -4942,7 +4942,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); @@ -5077,8 +5077,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