Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp787336iob; Wed, 18 May 2022 13:00:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzjWv/6MgS/z9h6AEiHmTk5QTV14GhQ/qJvbsT/tOnOfWHgsWZE74/EutkkmZ8loxSpnX2W X-Received: by 2002:a63:e218:0:b0:3c6:7449:15a2 with SMTP id q24-20020a63e218000000b003c6744915a2mr896988pgh.515.1652904038397; Wed, 18 May 2022 13:00:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652904038; cv=none; d=google.com; s=arc-20160816; b=nk/J71r6w+hk7dIQDXv646Np8I7O6O3HY4F9ElsGSle2w3437ry5HKueAl5pw5yNEi rCXl9cy1INToYoeoU4yBVso2++zL/bun4/3bm1pvtOOPYTEVF7rEuxP87hovK+cyVPZo 3WIA07LLZwiP1y8JSD0/Inzy0nCGoStx+agrN1BI27EgGcHdQjZ8zQf29S2Rh3skKUEj 0Gv/tR9wrNC8wwgmuG2z7AOEaHsEqyRAYkwIf9hzdcW5Nldg8Fp8bwMJVt89pV07YhrP 3kMGr+3MGA1M4QlF8LIU8I0tzTz+n+orOl9NB44keCP7L/M4+qVSrIj/475QBnnFHCaL cwHw== 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=aS7gQ5qpFeKUv7/KfR+Cnnmeed9eVIGi0Wg+eyJp4Fg=; b=IUHcLNbe6Bg57yc/q4/q7sk5bckOinEzTiMRb/QSgK8hLZueYvstESBT/uyMOYpeIs rSW42Bc97lPpxbu9CiBU0Rdw0BOD8jTmi95O4kL/SdVOBTkp0720HWHWzBjY22bpYTt/ 102tbJkyIDiAJWQlAAnEkE/G43pPEX15zQTq/63ERkW8Zx94JtR+fc8Bzq5RkJ1zwvwJ pnOVIvpRRBrIG3j5E3e+BNycteWVhKDzRB03eqdP4onlKBLYd/9XHGmEKre+uhfSch+G 8OlOT8ThiTI5w8cZ/+R30JjIwTJv3qiZfemUbpFk2flvZqeC42WDHk2vjM1PMvxgDHD0 XNMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DVKbEtQA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id u23-20020a631417000000b003c157112368si3373735pgl.609.2022.05.18.13.00.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 13:00:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=DVKbEtQA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4F767227824; Wed, 18 May 2022 13:00:36 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242278AbiERUA1 (ORCPT + 99 others); Wed, 18 May 2022 16:00:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242276AbiERUAZ (ORCPT ); Wed, 18 May 2022 16:00:25 -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 93E10227825 for ; Wed, 18 May 2022 13:00:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652904023; 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=aS7gQ5qpFeKUv7/KfR+Cnnmeed9eVIGi0Wg+eyJp4Fg=; b=DVKbEtQAoG29VWe0sk6PDmx7z37TsxseOtSv5Tltz5097mwWR6dGgWRqaU97WzOxwUpTA7 DGAhdpcys3tB5fgjgROKHxtRZr15aSW0rlEo1ZdQ1gW31juGDG0ROgf+/RPJVJKP97R7GE WqYwtAdXsJ40SSZCTTo5Hc6clw3G0yU= 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-31-HEMs9FENPBm7CP3UBs-DXA-1; Wed, 18 May 2022 16:00:18 -0400 X-MC-Unique: HEMs9FENPBm7CP3UBs-DXA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C54F818019D7; Wed, 18 May 2022 20:00:17 +0000 (UTC) Received: from asgard.redhat.com (unknown [10.36.110.4]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D5051492C14; Wed, 18 May 2022 20:00:13 +0000 (UTC) Date: Wed, 18 May 2022 22:00:10 +0200 From: Eugene Syromiatnikov To: Yonghong Song Cc: Jiri Olsa , Masami Hiramatsu , Steven Rostedt , Ingo Molnar , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , John Fastabend , KP Singh , netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH bpf v3 1/2] bpf_trace: check size for overflow in bpf_kprobe_multi_link_attach Message-ID: <20220518200010.GA29226@asgard.redhat.com> References: <39c4a91f2867684dc51c5395d26cb56ffe9d995d.1652876188.git.esyr@redhat.com> <412bf136-6a5b-f442-1e84-778697e2b694@fb.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <412bf136-6a5b-f442-1e84-778697e2b694@fb.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Spam-Status: No, score=-2.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Wed, May 18, 2022 at 09:34:22AM -0700, Yonghong Song wrote: > On 5/18/22 5:22 AM, Eugene Syromiatnikov wrote: > >- size = cnt * sizeof(*syms); > >+ if (check_mul_overflow(cnt, (u32)sizeof(*syms), &size)) > >+ return -EOVERFLOW; > > In mm/util.c kvmalloc_node(), we have > > /* Don't even allow crazy sizes */ > if (unlikely(size > INT_MAX)) { > WARN_ON_ONCE(!(flags & __GFP_NOWARN)); > return NULL; > } > > Basically the maximum size to be allocated in INT_MAX. > > Here, we have 'size' as u32, which means if the size is 0xffff0000, > the check_mul_overflow will return false (no overflow) but > kvzalloc will still have a warning. > > I think we should change the type of 'size' to be 'int' which > should catch the above case and be consistent with > what kvmalloc_node() intends to warn. Huh, it's a bitmore complicated as check_mul_overflow requires types to match; what do you think about + if (check_mul_overflow(cnt, (u32)sizeof(*syms), &size) || size > INT_MAX) ?