Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3582151iob; Tue, 17 May 2022 03:12:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw201V/JzUBuiiXJWNPqgZzW9DnuSJMueg0uK6fhxLDalAUyhZeTdzM4udqVgUJcsuIzLZI X-Received: by 2002:a17:907:6094:b0:6f4:aa0b:9af0 with SMTP id ht20-20020a170907609400b006f4aa0b9af0mr18508049ejc.432.1652782324847; Tue, 17 May 2022 03:12:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652782324; cv=none; d=google.com; s=arc-20160816; b=lqpU07s1khYQHvtEA9payNZLNYEIYSv0BHu29qASJ9pmrJWoB5/FnHrdAFMnII6ZJD ySY/sR3trRqZ2tc/TyReAS8Iziy7eoAwr19n1wx4Ojl5uWJhS+sCgpHIDm0yDCWezj5q SAiauwFH/f5WC3Zo5u8WHh7rknG26qCmVjCq73Jur5hbHFhwFBFKUL8Y/KJR9knJqfFw Y9F98KMoI1MA3kvIUHi8JcR0vcxrqCP8ew0i76ciAso2bUANlSO2uYn8Oc3pVSlvPAgP Y5YnZpXTrH+URYRdls7jVBen61tzy9Y9xe6gbPSIgt6CzVhifauH7Hp+wQMTx9y6xg+e Tqyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=z8TJGc65VPq8LFCB93HW2zYbRoFkSWlAyqA2j8NAtgg=; b=KwSh4gzCxgQ/o4jqxhjUHfSgUDdjqASbR04NcgTuI4iY8fTvIRa3VBGsH2hDvGF/Lq 4y0cayVFKkeqx0QCI97SYwCyjWWlE6ZB56Xs5/nECHXJVl/2NnKrDvorYd2mXKyiJOsK xvUsE5WmenEyaaKV0M+f0vBZXCdoKm8XSN0FLjVFaFSGZ9rYQBQrb8znevrfoYlpZ3G8 X61VXuoy/TzFlW0zLdURa/ZCInaEmNQeKY1QmfF9+4HvcyPxOK4kQtkztvsAsHJvZw4e S8WDy0O5KsBaxO8ipyPlatNn+RjdBPUwfzk2M5n0z16u0TkdV1yuYHwbIDhSevWJLnjZ Cm7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=hhghaI3I; 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 h20-20020a05640250d400b00426499ad159si14172104edb.162.2022.05.17.03.11.37; Tue, 17 May 2022 03:12:04 -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=hhghaI3I; 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 S241814AbiEQHhy (ORCPT + 99 others); Tue, 17 May 2022 03:37:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235250AbiEQHgl (ORCPT ); Tue, 17 May 2022 03:36: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 ESMTP id 6BC1C222B4 for ; Tue, 17 May 2022 00:36:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652772998; 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: in-reply-to:in-reply-to:references:references; bh=z8TJGc65VPq8LFCB93HW2zYbRoFkSWlAyqA2j8NAtgg=; b=hhghaI3IqtywUMrhE2LE4t0bc9NsTHxKy9xBBhlvpMeZJU6CkfMd7dirKKYQBjW2EkOc6z HxHEf/73MBAqGkMiLzfWBYNJJWPMRk1rAxk4j7//9btsNjHexN5H2kjl9vgpO5y4N2RfJg RTB/SOCE59qcD9NsLopxQtIMQXeyQjM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-250-kAUXOHQZNo-BaEpEg3KrOg-1; Tue, 17 May 2022 03:36:33 -0400 X-MC-Unique: kAUXOHQZNo-BaEpEg3KrOg-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 7C5131857F08; Tue, 17 May 2022 07:36:32 +0000 (UTC) Received: from asgard.redhat.com (unknown [10.36.110.3]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F15061568BA9; Tue, 17 May 2022 07:36:28 +0000 (UTC) Date: Tue, 17 May 2022 09:36:26 +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-next v3 2/4] bpf_trace: support 32-bit kernels in bpf_kprobe_multi_link_attach Message-ID: <525b99881dc144b986e381eb23b12617a311f243.1652772731.git.esyr@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 9c041be..a93a54f 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -2435,16 +2435,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; @@ -2454,6 +2450,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; @@ -2461,8 +2458,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; + } addrs = kvmalloc(size, GFP_KERNEL); if (!addrs) return -ENOMEM; @@ -2486,14 +2486,13 @@ 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 = 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