Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp15065536rwb; Mon, 28 Nov 2022 07:38:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf4qRV4iYpXK1kkXma4SeGlNz3ySiNJmR+DRhS/uU5wYrNk2p9NbpOolrb4jP+y7rYASP+cy X-Received: by 2002:a17:906:b14b:b0:78d:cede:91f4 with SMTP id bt11-20020a170906b14b00b0078dcede91f4mr43574922ejb.764.1669649936736; Mon, 28 Nov 2022 07:38:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669649936; cv=none; d=google.com; s=arc-20160816; b=Gu79JaBSpu53CIVrDIxJ3ePJQHaYT/wfTL6QrHV0Eo+BT7hEbwGcgO4VZGeqMIXcYq 2ivL+0ZoN9mRgyuQMnIKnqZ7IpWK0wcTlRKM21AjqLiI04PEgUWsxwAam761xzDCiXVO EKcT8M/tM0hm2i2rNU9qZ8iKmY9uQcHRYIprvBTmSNxNENQeaWKU+cFawHbfFj80FBAA w7mGp9tX8eIHZf4aYkgzR1zQDQWJG7DuFxxb5agHd6Dp8aJ3Zu15jBrCovWsQPOrvoXz bJyb5WtkbzaI7k1uyfBr+uY1PfMtg2+Te50JMsrpVF90pXLLVWMusOpstxlUkPlnmBz0 Stzg== 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=i+TN9hP6pZ4DRKDCz+V1dUYAB9I5oUrteAvF0crrcJI=; b=UBCJupxgODgMQFHoegKBpizsXvVDKb2VPx2uv2j/wuJh8Y/1ZJghprzlqSxgDz0/oZ 5N5VgqY88kGMDnB8qDwT8DGzDsx9zYuzaD3r7WIQ0jxJBrIEmnlaxQmBb44e9jPAlyg8 CHZWQH5MJ0EOLeHO4SrchjHnMRRDmwQZLFgF2aAbdSSWQkqi5A7V4MojoiijV9+RlBJe sYOAYqwEfSjUh4dggN/MXww1bEMTvwHYFVJc1HB96zmgbKT8SFlWXU2RAk+hdTCOBweT y7GEDw2PqH3TwM2z++S5AniWKMr3ls2FQn1vAIxs5Xw1nwzw2tNwCP34JUjk7CW4POdu yTEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=alzunQAh; 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 n3-20020aa7c443000000b0045d9ceae669si8871375edr.404.2022.11.28.07.38.34; Mon, 28 Nov 2022 07:38:56 -0800 (PST) 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=alzunQAh; 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 S230454AbiK1PMz (ORCPT + 85 others); Mon, 28 Nov 2022 10:12:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229670AbiK1PMv (ORCPT ); Mon, 28 Nov 2022 10:12:51 -0500 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 E360620986 for ; Mon, 28 Nov 2022 07:12:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669648319; 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=i+TN9hP6pZ4DRKDCz+V1dUYAB9I5oUrteAvF0crrcJI=; b=alzunQAhskjQiS5PphfPxaf1jc5p4R/T7WY/ApzVORF2djwju53dC52XfTCZ2r+3fN/MLs NMcl8IMBR4dYQXG2MFbaPe2xQPKGUiodETpm3qW6OJqLm5WBtjRuOhM3Y5XZZa3obBDKmX WnGwrmkqQ9oYlreoVhzd08KWof4NU8U= 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-558-XLRQ24AjN--Pt_9xiqlJYg-1; Mon, 28 Nov 2022 10:11:56 -0500 X-MC-Unique: XLRQ24AjN--Pt_9xiqlJYg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BEFB33C0DDA5; Mon, 28 Nov 2022 15:11:55 +0000 (UTC) Received: from [10.22.10.34] (unknown [10.22.10.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA8611121314; Mon, 28 Nov 2022 15:11:54 +0000 (UTC) Message-ID: Date: Mon, 28 Nov 2022 10:11:52 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH-tip v4] sched: Fix NULL user_cpus_ptr check in dup_user_cpus_ptr() Content-Language: en-US To: Will Deacon Cc: Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Phil Auld , Wenjie Li , =?UTF-8?B?RGF2aWQgV2FuZyDnjovmoIc=?= , linux-kernel@vger.kernel.org References: <20221125023943.1118603-1-longman@redhat.com> <92b99a5e-1588-4e08-a652-72e9c51421cf@redhat.com> <20221128120008.GA25090@willie-the-truck> From: Waiman Long In-Reply-To: <20221128120008.GA25090@willie-the-truck> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Spam-Status: No, score=-2.4 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_H2,SPF_HELO_NONE,SPF_NONE 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 11/28/22 07:00, Will Deacon wrote: > On Sun, Nov 27, 2022 at 08:43:27PM -0500, Waiman Long wrote: >> On 11/24/22 21:39, Waiman Long wrote: >>> In general, a non-null user_cpus_ptr will remain set until the task dies. >>> A possible exception to this is the fact that do_set_cpus_allowed() >>> will clear a non-null user_cpus_ptr. To allow this possible racing >>> condition, we need to check for NULL user_cpus_ptr under the pi_lock >>> before duping the user mask. >>> >>> Fixes: 851a723e45d1 ("sched: Always clear user_cpus_ptr in do_set_cpus_allowed()") >>> Signed-off-by: Waiman Long >> This is actually a pre-existing use-after-free bug since commit 07ec77a1d4e8 >> ("sched: Allow task CPU affinity to be restricted on asymmetric systems"). >> So it needs to be fixed in the stable release as well. Will resend the patch >> with an additional fixes tag and updated commit log. > Please can you elaborate on the use-after-free here? Looking at > 07ec77a1d4e8, the mask is only freed in free_task() when the usage refcount > has dropped to zero and I can't see how that can race with fork(). > > What am I missing? I missed that at first. The current task cloning process copies the content of the task structure over to the newly cloned/forked task. IOW, if user_cpus_ptr had been set up previously, it will be copied over to the cloned task. Now if user_cpus_ptr of the source task is cleared right after that and before dup_user_cpus_ptr() is called. The obsolete user_cpus_ptr value in the cloned task will remain and get used even if it has been freed. That is what I call as use-after-free and double-free. Cheers, Longman