Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1270379imu; Wed, 9 Jan 2019 15:01:10 -0800 (PST) X-Google-Smtp-Source: ALg8bN7rLIu13fKFWl4vDxEmTBwCMjPA1F4twl5iCls2NbuXkWSNOQDWVLnAZy+HwXSjT5/d1kPM X-Received: by 2002:a63:cb4a:: with SMTP id m10mr6865464pgi.105.1547074870890; Wed, 09 Jan 2019 15:01:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547074870; cv=none; d=google.com; s=arc-20160816; b=qUnk0HYA3Bt4YeDLR0aclLojoSnOP72+fiPSr988ndOmNz+xi0uXXZHYtWtQH6Hsnc zpP/aEU12/BaUPdKSp6ybekQ5RlE7o/DWaeOyU4dQ7FyXjjWj7IgHvGvxIaXtOT/nIyI k41bL9bXkwvA6EyeQ5scXryimf6H9fOTkC+Q5MEjhj1y2jMpOG5mmGPLZbd0K5sBgU9g ZUhwzRizQYwkGA7YZv13MCLQCYAeL/qIbVGabw12G5cTKWlroZ/2YyEJhr+TCrs079eG yB8ZY6h0QPNk44tlpuFwNeyzfLmpqmSxZ6ir9xUvvC+T8A2LT+DmVFWPg89VfjJAYIOz G3Jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=2E4xn2izlEUg+62TcYlL7VvJukCVkfj6sZDpb1WHghE=; b=n4sS0x6lEhcI3z3PxHZ3NXOLj/ngX7tTq3IL8+NuxEaO+dwcxpwTmoc+uB357yMWyS r1qcUAB2T+PBmtnmNlR0r8hi5m0HGRcFngNN6PnuOfMNZgFFHOndEFfCJ46jZwR6u9y5 cKGGShlVKNP0FPLlR/+Hn/fuVZXi2HP+78t3xLPPi82LQABg1Dcl+okWk4KMhQYhoWJq KARZio2PnqE5envBVw8HeONH2n14J2cxmF0hb15EbzseGCjHgelr7euP7VRyPc/nXGkD BpQzbe7SIfc5MS4ixaaJlKX/5d8HofN0067QGxY8wBJ6sMb+MaX69HDtITn6A2StidAa NaxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=fjF9Zw7o; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d8si30598934pln.128.2019.01.09.15.00.55; Wed, 09 Jan 2019 15:01:10 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@sargun.me header.s=google header.b=fjF9Zw7o; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727218AbfAIWnG (ORCPT + 99 others); Wed, 9 Jan 2019 17:43:06 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:35617 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726456AbfAIWnF (ORCPT ); Wed, 9 Jan 2019 17:43:05 -0500 Received: by mail-ed1-f68.google.com with SMTP id x30so8676467edx.2 for ; Wed, 09 Jan 2019 14:43:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=2E4xn2izlEUg+62TcYlL7VvJukCVkfj6sZDpb1WHghE=; b=fjF9Zw7oCvlPGXjuOhL+ZHZvm/7NCC3idKqLJoVGPs2Kwg6P3hF2iIS9Cf7NH+xhmG HPCX9K0mTx/mwEThz7H8fC2moaLw9Drx+ObJ8pjSOGNAjmnmsWLJhED5FP4+Da7Yp3M5 2VcA6dQQOrnYe+1fEGQZWKeAkMbD0fpRVDgvg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=2E4xn2izlEUg+62TcYlL7VvJukCVkfj6sZDpb1WHghE=; b=nEwqOict2YjYXcOYf+NGNKKqui4o1FYVC0XVCLCzCBdkcUQa2fWkdfhZDRM2jQGZA+ cWu2VV7qa5B+lZv+v1hSwNJX5Kwv5O9g9OyAy6vMTc58A2JRyJkth2/FiprqeqpeMg9Y lzZP/njFMdFO1h1HJbKJSzZrVMv/PKUXL+kgS6+2eYbbkBKM7NLOBcSlMrV4RwNoOqNz C9JcoGdDs9JxcRmduPAW0GIK0n4Q5WLkENHST3zjOK7siptAk+fJu0IJUjquOnz1q2je PQUFGUxPQ/Qq9i9qs+W7vErrImzsOmu9nMKnzR2qSInQKSvMSnhV3XfAUSsyXPx/WWCE WsJQ== X-Gm-Message-State: AJcUukcMgwlGdQ3pcfyDEzQ5lOMPgVYsIjdLOaNLyO7a/8rOBtgQa7Wx 4MEz1wJ5UhjshHCQUJYdjo4WmgWyjsTp3RvntY5rW/9a9iQ= X-Received: by 2002:a50:b881:: with SMTP id l1mr7436011ede.167.1547073783723; Wed, 09 Jan 2019 14:43:03 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Sargun Dhillon Date: Wed, 9 Jan 2019 14:42:27 -0800 Message-ID: Subject: Re: Crash in list_add_leaf_cfs_rq due to bad tmp_alone_branch To: LKML , Ingo Molnar , Peter Zijlstra , Tejun Heo , Peter Zijlstra , Gabriel Hartmann , gabriel.hartmann@gmail.com Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 9, 2019 at 2:14 PM Sargun Dhillon wrote: > > I picked up c40f7d74c741a907cfaeb73a7697081881c497d0 sched/fair: Fix > infinite loop in update_blocked_averages() by reverting a9e7f6544b9c > and put it on top of 4.19.13. In addition to this, I uninlined > list_add_leaf_cfs_rq for debugging. > > This revealed a new bug that we didn't get to because we kept getting > crashes from the previous issue. When we are running with cgroups that > are rapidly changing, with CFS bandwidth control, and in addition > using the cpusets cgroup, we see this crash. Specifically, it seems to > occur with cgroups that are throttled and we change the allowed > cpuset. > This patch from Gabriel should fix the problem: [PATCH] sched/fair: Reset tmp_alone_branch on cfs_rq delete When a child cfs_rq is added to the leaf cfs_rq list before its parent tmp_alone_branch is set to point to the child in preparation for the parent being added. If the child is deleted before the parent is added then tmp_alone_branch points to a freed cfs_rq. Any future reference to tmp_alone_branch will result in a use after free. Signed-off-by: Gabriel Hartmann Reported-by: Sargun Dhillon --- kernel/sched/fair.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 7137bc343b4a..0987629cbb76 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -347,6 +347,11 @@ static inline void list_add_leaf_cfs_rq(struct cfs_rq *cfs_rq) static inline void list_del_leaf_cfs_rq(struct cfs_rq *cfs_rq) { if (cfs_rq->on_list) { + struct rq *rq = rq_of(cfs_rq); + + if (rq->tmp_alone_branch == &cfs_rq->leaf_cfs_rq_list) + rq->tmp_alone_branch = &rq->leaf_cfs_rq_list; + list_del_rcu(&cfs_rq->leaf_cfs_rq_list); cfs_rq->on_list = 0; }