Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp5562716pxb; Mon, 7 Feb 2022 05:02:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmTqxsWwpUDi5asLDqGd9/+rMXI0OjOFXi0RlCHnmR8ycRg4YDqXposWHN6ofjBBkJJM4H X-Received: by 2002:a17:903:2486:: with SMTP id p6mr4546792plw.1.1644238928146; Mon, 07 Feb 2022 05:02:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644238928; cv=none; d=google.com; s=arc-20160816; b=NAALi0p7+k9rZwVCYGHqrKEbt17B2/J6+rULs7Znh5F+IG5WqKfI3NomZxmxc+5l62 N4ttdEQ5KbpReRqsU/JGGWEzDozsGADPWiBKkuGgTDryv01vlmK+ILqWH2M6afWE5rV3 mcTolEdlfJtneXJ5euGiUAO1FjTW0O9K557a2mYONbgQsANJaDX2pHTwRWL91Jmaggpd N/tSs5dGDweTXp8Z2om8GgF+pKxXl3R/Q/Nq/kkCxpYr8utnW1QLDJwEhfzbUDfY73DQ SovtJ96nbIkbm+LRr/6AfljSAIAenxvII7g1gvUCEJJ6a81HXdvKd79skO/Un/0cxFyN dwqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=GM+AIngVLb5co1+/1JjleFul0NTmgZBJcvh511LC0FI=; b=SsiCWGxcJOyXaQDvQwkT+efrY8DKtCM+d4qfsj/r9VMG45fcxy9pMvaB7tUIzMyo9u rnt1UicmhLpWNajJbRLLnPhQ2rtyVj8TJsAMEXc2jey/cO3pANnsbnNCChRXLro03bZQ 52+FptvW+IN+a31GCJ6BzTDP5rcqZcKPFQmWSNvxZHpgkIlCjVwnPmIHH7k3Uh5hQXnN DX7qxCw1aBF88iVcNaFvRDX1jUBBgPSzM6GW8ktRoRK9rTAEl2VLuFmqpEnhHevZBEKE n9wXhUjg8nYi1piOihscl6xwVWtYDSY5blwa2w6oukWExPoChwzQ1N+6MyKyn1CbxaNH 20/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ALzcV2fG; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s14si10556746plg.205.2022.02.07.05.01.47; Mon, 07 Feb 2022 05:02:08 -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=@infradead.org header.s=casper.20170209 header.b=ALzcV2fG; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240024AbiBFNoD (ORCPT + 99 others); Sun, 6 Feb 2022 08:44:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239964AbiBFNoC (ORCPT ); Sun, 6 Feb 2022 08:44:02 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01676C06173B; Sun, 6 Feb 2022 05:44:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=GM+AIngVLb5co1+/1JjleFul0NTmgZBJcvh511LC0FI=; b=ALzcV2fG8HNpzLUkt0hl601RL0 5sC0XTXDlw4SthUqwIUcyuC6MSt/QbY03gw7NnrH7FQ07LegJsnndDZw7tFPhwScRGLrEEw5RG0R/ vvDGOvAn5kIKjNiYe5kbjtPa0Um0vyF3Atz4TwrGNZq3XE8w/TJ9A4zis74f7g6MrpPOm3T5V5uqk yJns1T9R2eacq/VLvVb89MLSQnJ2o9c49S48pSjze+2lOKbaTbhnjvZqrCulXqrig42/J2+ZPv2x+ SAz2sAE2R04lK0t4cHNyPXqPZAiFulEpNp+TTHJc+xYboXPDo4ByMjSefohwrc9fQGqSiXut8Xhzp ZRZjKKIA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nGhpE-00EF76-3c; Sun, 06 Feb 2022 13:43:32 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 1ADC1300470; Sun, 6 Feb 2022 14:43:29 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id D09732CA50E34; Sun, 6 Feb 2022 14:43:29 +0100 (CET) Date: Sun, 6 Feb 2022 14:43:29 +0100 From: Peter Zijlstra To: Tadeusz Struk Cc: Ingo Molnar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Zhang Qiao , stable@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+af7a719bc92395ee41b3@syzkaller.appspotmail.com Subject: Re: [PATCH v5] sched/fair: Fix fault in reweight_entity Message-ID: References: <20220203161846.1160750-1-tadeusz.struk@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220203161846.1160750-1-tadeusz.struk@linaro.org> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 Thu, Feb 03, 2022 at 08:18:46AM -0800, Tadeusz Struk wrote: > Syzbot found a GPF in reweight_entity. This has been bisected to commit > 4ef0c5c6b5ba ("kernel/sched: Fix sched_fork() access an invalid sched_task_group") > > There?is a race between sched_post_fork() and setpriority(PRIO_PGRP) > within a thread group that causes a null-ptr-deref?in reweight_entity() > in CFS. The scenario is that the main process spawns number of new > threads, which then call setpriority(PRIO_PGRP, 0, -20), wait, and exit. > For each of the new threads the copy_process() gets invoked, which adds > the new task_struct and calls sched_post_fork() for it. > > In the above scenario there is a possibility that setpriority(PRIO_PGRP) > and set_one_prio() will be called for a thread in the group that is just > being created by copy_process(), and for which the sched_post_fork() has > not been executed yet. This will trigger a null pointer dereference in > reweight_entity(),?as it will try to access the run queue pointer, which > hasn't been set. This results it a crash as shown below: > > > Before the mentioned change the cfs_rq pointer for the task has been > set in sched_fork(), which is called much earlier in copy_process(), > before the new task is added to the thread_group. > Now it is done in the sched_post_fork(), which is called after that. > To fix the issue the remove the update_load param from the > update_load param() function and call reweight_task() only if the task > flag doesn't have the TASK_NEW flag set. > > Link: https://syzkaller.appspot.com/bug?id=9d9c27adc674e3a7932b22b61c79a02da82cbdc1 > Fixes: 4ef0c5c6b5ba ("kernel/sched: Fix sched_fork() access an invalid sched_task_group") > Reported-by: syzbot+af7a719bc92395ee41b3@syzkaller.appspotmail.com > Reviewed-by: Dietmar Eggemann > Signed-off-by: Tadeusz Struk Thanks!