Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32556768rwd; Fri, 7 Jul 2023 16:28:32 -0700 (PDT) X-Google-Smtp-Source: APBJJlE9ZtLODCr/6jmIPvDURvX5fuANlE2KoetD4i9gX3hxcty+Esxbi1U1xD93dcmGi/QHE17C X-Received: by 2002:a17:907:9251:b0:992:ef60:aae0 with SMTP id kb17-20020a170907925100b00992ef60aae0mr4797660ejb.54.1688772512081; Fri, 07 Jul 2023 16:28:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688772512; cv=none; d=google.com; s=arc-20160816; b=xE38EIRDnxwSupjGYir4qiwCdFqqUF6qbjeQpGlsl/xAfs2uoxpHDV08zUwUKGutM2 l0Kt4gHnqUtJoMX3TynbibjUYurYrAS4Gg4oQdnsy6HvETnTqQuDjuI3f6meGd0SYCjr b3VVkHAsXG6mH8070hhnmrMFAc+M2mma7pH/m3gNsZRERK6zDjvfvAAdySfeYkip2/c+ euZpyyGJMN+kFeT+c/RvfrR0T84/GBl3/neZsUlTB22wRaaHs0Yu8HsOP8WXRoqatm+a hvPx9NZz+UxJR5Wjruc5dQCVJItlPOR8c3CiUyfjfRDb+i7G6HvQAbS3gbDGWQZ/azLp Jhmg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=XNAe7PgV0fkePnBzfDbEzA+U1/1CfkmWpKX+HX/k7jo=; fh=6FPt++cTFkhgvao2BxnNd+Y1j+SMgyeX5agmO6WuigE=; b=x1ctJXlvqQWmTa9FMJhsaJKdQuRA5xv4UknsbgMdC7tsvIvPfLKIIluFTyD8+M0BXQ /aYefPip6KMtTQnZhBFUyBc8JCkRCxJX/Xnk3hyTlryiKRVKxVNY3nHAdoqsIIkVRish cffCqcROUxz8Jg/b9kyxgeyfyRywlj2vk8DynnB2N3Cm14wguxBASxAeM8WflbXrA4xn IDcAFATxZ0MsW6lliuIaHkPDGHaPjXt2fbZZEvagVxGVAqqMtDbehgtVbxK3JtaefzzP QsprsaWkgotFa77gl3F9+a2hxqR/aAjUXYRDEhag/L0iitaYMZQTtko8nQ2QBSVMdUVi F/AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=dKQlr39M; 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 v22-20020a17090690d600b0099381745ba1si1578860ejw.887.2023.07.07.16.28.04; Fri, 07 Jul 2023 16:28:32 -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=dKQlr39M; 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 S230163AbjGGXYx (ORCPT + 99 others); Fri, 7 Jul 2023 19:24:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229643AbjGGXYu (ORCPT ); Fri, 7 Jul 2023 19:24:50 -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 ESMTPS id 5B25C2106 for ; Fri, 7 Jul 2023 16:24:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688772242; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XNAe7PgV0fkePnBzfDbEzA+U1/1CfkmWpKX+HX/k7jo=; b=dKQlr39MqvEISdaVAJyq4n2uZQ/3nAcaIeqHKLfJiioc9+ZwQ30XfovoHPHUtCw+209zxY jRN9RbxfBjjwvvVeii6/Hw3gB2RVYMl+KZHXooyvK4I3ahX2TRKpN/7Muldd4u8xF67rNO 87tnaoyngRvoNy76BxGY8nKSJibdLsk= 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-214--j3nidQAMjSc7kd_HMjhaw-1; Fri, 07 Jul 2023 19:24:00 -0400 X-MC-Unique: -j3nidQAMjSc7kd_HMjhaw-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 864CD380451E; Fri, 7 Jul 2023 23:24:00 +0000 (UTC) Received: from [10.22.34.12] (unknown [10.22.34.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5737BF643A; Fri, 7 Jul 2023 23:24:00 +0000 (UTC) Message-ID: <9a3cb0c2-0b1a-28d0-0ebf-c29c6cb37f29@redhat.com> Date: Fri, 7 Jul 2023 19:24:00 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [BUG 6.4] sched/core: Possible buffer overflow in do_set_cpu_allowed Content-Language: en-US To: Joe Korty Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Ingo Molnar References: <20230707202851.GA4231@zipoli.concurrent-rt.com> From: Waiman Long In-Reply-To: <20230707202851.GA4231@zipoli.concurrent-rt.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE 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 On 7/7/23 16:28, Joe Korty wrote: > In commit 9a5418bc48bab ("sched/core: Use kfree_rcu() in > do_set_cpus_allowed()"), a kfree_rcu() is used to free a cpu mask. > However, cpu masks can be as short as 8 bytes and this is a problem, > as kfree_rcu requires the to-be freed buffer to be at least 16 bytes. > Thus there is a chance of buffer overflow corruption when the number of > possible cpus in the system is 64 or less. > > I have not seen this corruption in the wild. I only noticed this possibility > when reviewing the scheduler differences between 6.1 and 6.4. We were aware of this known limitation. If you look at alloc_user_cpus_ptr(): static cpumask_t *alloc_user_cpus_ptr(int node) {         /*          * See do_set_cpus_allowed() above for the rcu_head usage.          */         int size = max_t(int, cpumask_size(), sizeof(struct rcu_head));         return kmalloc_node(size, GFP_KERNEL, node); } We made sure that the allocated buffer is big enough to hold struct rcu_head. Cheers, Longman