From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BA0A0C001B2 for ; Thu, 22 Dec 2022 20:17:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235644AbiLVURO (ORCPT ); Thu, 22 Dec 2022 15:17:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229783AbiLVURI (ORCPT ); Thu, 22 Dec 2022 15:17:08 -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 48CEBFD1F for ; Thu, 22 Dec 2022 12:16:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671740181; 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=e6xBxYFAMVlhbpKMfEQCPQ1Pgjllc4ppXfabrgMIyFA=; b=LIQdADb1E61f9fwQ8n9F3DGWEK3f2pN7toRwkcjpyWVS3OUfSDd0aSVV+4nmhSIbVtJC80 S5eJStkxTO2dan6ztxx8DDCTYak9phurUgqrotU0IW43t0js3d6RPkkD8iAIrUs3PApD5E 0k6yqtof5ZijAPM8Km9bwqoOOrRHcI8= 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-572-xbPFMbCcPDWhbwxhLollgw-1; Thu, 22 Dec 2022 15:16:17 -0500 X-MC-Unique: xbPFMbCcPDWhbwxhLollgw-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 DF6398533AE; Thu, 22 Dec 2022 20:16:16 +0000 (UTC) Received: from [10.22.33.48] (unknown [10.22.33.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1DBB8492B00; Thu, 22 Dec 2022 20:16:16 +0000 (UTC) Message-ID: <0b70f4c8-55ce-a5cd-cab7-7dfe70e60e99@redhat.com> Date: Thu, 22 Dec 2022 15:16:15 -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 v2] sched: Fix use-after-free bug in dup_user_cpus_ptr() Content-Language: en-US To: Peter Zijlstra Cc: Ingo Molnar , 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, stable@vger.kernel.org References: <20221205164832.2151247-1-longman@redhat.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/22/22 14:34, Peter Zijlstra wrote: > On Mon, Dec 05, 2022 at 11:48:32AM -0500, Waiman Long wrote: >> Since commit 07ec77a1d4e8 ("sched: Allow task CPU affinity to be >> restricted on asymmetric systems"), the setting and clearing of >> user_cpus_ptr are done under pi_lock for arm64 architecture. However, >> dup_user_cpus_ptr() accesses user_cpus_ptr without any lock >> protection. When racing with the clearing of user_cpus_ptr in >> __set_cpus_allowed_ptr_locked(), it can lead to user-after-free and >> double-free in arm64 kernel. > How? the task cannot be in migrate_enable() and fork() at the same time, > no? > I believe a task A can call sched_setaffinity() to modify the cpu affinity of a different task, say B, which can be under fork() at the same time. So we need to use the pi_lock to synchronize the access of user_cpus_ptr to avoid the kind of race that can cause double-free. Cheers, Longman