Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3091622iob; Mon, 16 May 2022 12:53:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlkuDmRXdzZXlH+Sl9ApAfJ4KSeg38rD4Zo0OupAnn3J3AG8gHIZ6TEuTpspafd45+Z0CW X-Received: by 2002:a17:902:d551:b0:15e:c50f:41b5 with SMTP id z17-20020a170902d55100b0015ec50f41b5mr19117324plf.98.1652730837335; Mon, 16 May 2022 12:53:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652730837; cv=none; d=google.com; s=arc-20160816; b=albBaTGOso/rxz62gOUkbl65bQgW8Q6lJkmKsofmVDeeL7hPtOgwSp8hbk7PtioN1x 6NRhAvSvYJKi6vJl23/nK/TU4nDLOzJDanQQux2J5T9dgWDkaJ/Zlm7vHMcCexByPBI8 PufHGbdDBUPxLR0/bbLEtEAKImzneJpSBpXcma+GPH9Yz8CL7eC4sWEGpeM+eOFYRj62 4w9sw460awPI8d7bv8qwp/xnKbky2sqNbEQ73cGXxeFe5iXTRXw3OgHuhp4Z3fjJiv4V Gm0NAW9zXXLJ+4BK3uWu5wGpUAnJiyUP5MtTsUpgKEzot7WRCGOJtQ0VBpJZjAM3WgGl rHBw== 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=i9tbH4DATFTVHTVKDZDsmCN1LCos1kVSdRdRXbhuGME=; b=SuvxnRbGryREgvnLH/6+TaNAjEuyb18S6MYFOn3pbun+0wNwoTWvzqEGhL2k4DVQyf bFvLQHVcCkV8FFpM1INeteAKyzxjvuqh3jnIKdK7LJr9afV4vct4uzc/c/8XMpuBIjTy 7JsIg7iAW886s+yPqC6MOKcUN2SRw1nGAgZs5nnK4JJCdpTMe1iQE/pRGhI8mQg+jlX2 CtUvmdTKjB/DiE82NsBZ2E49XYc6j2mttnOeuWf85nvdfFhnOkhCG9CjYEf22gCtJdUD 73X9DO8Or6Mru/PLddybNyGvYVvKhQsBY0qHTlrmebr042cp+kAskQa969xjHH0pJRIp f8VA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=UnSTsSqo; 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 u4-20020a62ed04000000b0050e0b4a4721si13142144pfh.277.2022.05.16.12.53.46; Mon, 16 May 2022 12:53:57 -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=UnSTsSqo; 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 S1344819AbiEPS1v (ORCPT + 99 others); Mon, 16 May 2022 14:27:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46290 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344804AbiEPS1p (ORCPT ); Mon, 16 May 2022 14:27:45 -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 A02A13DDE5 for ; Mon, 16 May 2022 11:27:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652725660; 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=i9tbH4DATFTVHTVKDZDsmCN1LCos1kVSdRdRXbhuGME=; b=UnSTsSqoZk4dUnMa7f21IawQV1ijFWWRVdARs5lD6MUu3oo6P8bhlMCYJGCeedfusmaLhd Iix2/+x/dT3/o6J5vgtRpN+PCqSJm89frVPOkQEWKqUxaiv0+zPflsBYuM197EWv65xmmU vZ1RUDwwZGF9AOryE7IBqSNL+TL7qCA= 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-623-gLZIfmtbMiOoh8UQfzAPbw-1; Mon, 16 May 2022 14:27:35 -0400 X-MC-Unique: gLZIfmtbMiOoh8UQfzAPbw-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 9BB953C6053D; Mon, 16 May 2022 18:27:34 +0000 (UTC) Received: from asgard.redhat.com (unknown [10.36.110.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1DD3F153B8B8; Mon, 16 May 2022 18:27:29 +0000 (UTC) Date: Mon, 16 May 2022 20:27:27 +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 2/4] bpf_trace: support 32-bit kernels in bpf_kprobe_multi_link_attach Message-ID: <20220516182727.GA29647@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 e90c4ce7..d228440 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2405,16 +2405,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; @@ -2424,6 +2420,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; @@ -2431,8 +2428,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) @@ -2449,14 +2449,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