Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3355913iob; Mon, 16 May 2022 20:30:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGjpbOHu4IhTyp5bYn4hk/MtMJwQx1gT43KH0mZH5meXoiHE9tzEx86rQ6IP1TZS9cydBj X-Received: by 2002:a05:6402:4391:b0:427:f2f0:607b with SMTP id o17-20020a056402439100b00427f2f0607bmr16489316edc.45.1652758250959; Mon, 16 May 2022 20:30:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652758250; cv=none; d=google.com; s=arc-20160816; b=Zqxqp4lSYaCBnNz2paON5hP196Yj9QgJLtL3lzs8JSCpkRWsOa4X1ElrHy3OxdPE3n KziSmqiHKcAODYEJntGjVOUBgN0quyiRB9FY3N77/bvdwwGtHVzNPkcbauWvzYS7ortM ZUm0e/qXYMDSZCXwVBfm/fRI4BFq5xZQQ4mzTcrYIz+bUOgOSpd7Y2w6gzZs1c95/pP9 TNeO5ose39nDHNGKyZThB3o5kmPzCeSZQD2kfh7FspjQf3XqIDxewngDUScOz1YRBmgz RklwppsP1zOmhvFutz7j5yDZpI1qp2djexay9CRj/x40wiIMe62Qsc3novrtibFDkryN tH0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:content-disposition:mime-version :message-id:subject:cc:to:from:date:dkim-signature; bh=shvwfut6i8VPs3cAVyDak3cwO9KQU+d8ysvDzTvpaAA=; b=FeujPHYesifhyKPTdVS2Jc2Gdls0kHHVBIwyb30+K7H3UEuvTk2QnOtyt4X2eoTcZJ ZHYAW1gPPI6hj/UFJ0J6GtpnZZdaqC7Zo7SJ3n3engFsD/VeKHVc5Hd5SOUe6oXhHj6z FegH/csJruu+rTN6PO41uQGBL0vAv0dRTUP4w7jO5TM3B/5NIBBAQvToKuNuYcx0OkOA LjOdZ661ENLlRKskkzlW3uFGAm3yWfUuXC4Jk0sDwlFPikeT0+HvcDhOSbHsG2IM9sdU 9cF4sOfSISG6js3a8vuk1Dh3blnxZcC6gOIdmv2sqZ6wVdp4ymlcYZeibQVzCF33ZiIh G75w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DEsqZ0bJ; 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 j21-20020aa7c0d5000000b0042aae340f78si5532330edp.89.2022.05.16.20.30.26; Mon, 16 May 2022 20:30:50 -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=DEsqZ0bJ; 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 S1350128AbiEPXFh (ORCPT + 99 others); Mon, 16 May 2022 19:05:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350057AbiEPXFe (ORCPT ); Mon, 16 May 2022 19:05:34 -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 ESMTP id 933B94665B for ; Mon, 16 May 2022 16:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652742319; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=shvwfut6i8VPs3cAVyDak3cwO9KQU+d8ysvDzTvpaAA=; b=DEsqZ0bJd9qxTv2mXQ27LkW5UFYPvKCwZpcyfIK4yIPUrfQBNzlhB1QInOLDgkUlZLHfoS XP9KCvL8ZcL30w3Fzzl115VJ5a2aRv/Ztq8DhB+x92azKeCj2F04p6oK31d8aTfYUMWZ6O zAMJc+4tkaB65xfLMnrGD9dGuPnOg24= 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-664-3WHrexlZPXOqCxQ8_rX5Ng-1; Mon, 16 May 2022 19:05:14 -0400 X-MC-Unique: 3WHrexlZPXOqCxQ8_rX5Ng-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7E3971D96CA2; Mon, 16 May 2022 23:05:13 +0000 (UTC) Received: from asgard.redhat.com (unknown [10.36.110.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6D5F11551CF2; Mon, 16 May 2022 23:05:09 +0000 (UTC) Date: Tue, 17 May 2022 01:05:06 +0200 From: Eugene Syromiatnikov To: Jiri Olsa , Masami Hiramatsu , Steven Rostedt , Ingo Molnar , Alexei Starovoitov , Daniel Borkmann Cc: Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Shuah Khan , linux-kselftest@vger.kernel.org Subject: [PATCH bpf v2 2/4] bpf_trace: support 32-bit kernels in bpf_kprobe_multi_link_attach Message-ID: <20220516230506.GA25374@asgard.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 X-Spam-Status: No, score=-3.1 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,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 It seems that there is no reason not to support 32-bit architectures; doing so requires a bit of rework with respect to cookies handling, however, as the current code implicitly assumes that sizeof(long) == sizeof(u64). Signed-off-by: Eugene Syromiatnikov --- kernel/trace/bpf_trace.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index f1d4e68..bf5bcfb 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2406,16 +2406,12 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr struct bpf_link_primer link_primer; void __user *ucookies; unsigned long *addrs; - u32 flags, cnt, size; + u32 flags, cnt, size, cookies_size; void __user *uaddrs; u64 *cookies = NULL; void __user *usyms; int err; - /* no support for 32bit archs yet */ - if (sizeof(u64) != sizeof(void *)) - return -EOPNOTSUPP; - if (prog->expected_attach_type != BPF_TRACE_KPROBE_MULTI) return -EINVAL; @@ -2425,6 +2421,7 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr uaddrs = u64_to_user_ptr(attr->link_create.kprobe_multi.addrs); usyms = u64_to_user_ptr(attr->link_create.kprobe_multi.syms); + ucookies = u64_to_user_ptr(attr->link_create.kprobe_multi.cookies); if (!!uaddrs == !!usyms) return -EINVAL; @@ -2432,8 +2429,11 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr if (!cnt) return -EINVAL; - if (check_mul_overflow(cnt, (u32)sizeof(*addrs), &size)) + if (check_mul_overflow(cnt, (u32)sizeof(*addrs), &size) || + (ucookies && + check_mul_overflow(cnt, (u32)sizeof(*cookies), &cookies_size))) { return -EOVERFLOW; + } size = cnt * sizeof(*addrs); addrs = kvmalloc(size, GFP_KERNEL); if (!addrs) @@ -2450,14 +2450,14 @@ int bpf_kprobe_multi_link_attach(const union bpf_attr *attr, struct bpf_prog *pr goto error; } - ucookies = u64_to_user_ptr(attr->link_create.kprobe_multi.cookies); if (ucookies) { - cookies = kvmalloc(size, GFP_KERNEL); + cookies_size = cnt * sizeof(*cookies); + cookies = kvmalloc(cookies_size, GFP_KERNEL); if (!cookies) { err = -ENOMEM; goto error; } - if (copy_from_user(cookies, ucookies, size)) { + if (copy_from_user(cookies, ucookies, cookies_size)) { err = -EFAULT; goto error; } -- 2.1.4