From nobody Sat May 10 05:26:51 2025 Delivered-To: importer2@patchew.org Received-SPF: pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; envelope-from=linux-kernel-owner@vger.kernel.org; helo=vger.kernel.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org ARC-Seal: i=1; a=rsa-sha256; t=1610818717; cv=none; d=zohomail.com; s=zohoarc; b=T8wqunw9on49z38nk/bUVgfcbj+nQNX/bogivRxiGMyAKAH8RJpFHvBlSpboUo4m5J0p3OCT2pGhLxHe4GZWvAKoz6IL+jtBVxHH5vZTgwwsxr578X4wueFs/X7+/n9NfA5LjTsQPROMaKyuOk48SBQchMlgd2cXDYEEbigL2UA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1610818717; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:MIME-Version:Message-ID:References:Subject:To; bh=mxEgYGcQCZYKbRq3K2ngs08xWDWh3dTlzcMk23rneeQ=; b=DkBlORH6MTwn5mMsklZoVJB1tGSKI2WaX7ut/m95hsCvcggasuZtEaLta5GxbCuZ8Q3ZAo7CLZkJvB81kDSWvMJqPyPMIE5HtetfxGEzHASfF1HNvwtzmhDIMZRyG2aaVCwBiC+r8OuRbOJnNuL2gUneHFjczKboSSE2ij2T/eg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mx.zohomail.com with SMTP id 1610818717501357.95772000627096; Sat, 16 Jan 2021 09:38:37 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727479AbhAPRif (ORCPT ); Sat, 16 Jan 2021 12:38:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727134AbhAPRif (ORCPT ); Sat, 16 Jan 2021 12:38:35 -0500 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78854C061757 for ; Sat, 16 Jan 2021 09:37:55 -0800 (PST) Received: by mail-lf1-x131.google.com with SMTP id 23so17920465lfg.10 for ; Sat, 16 Jan 2021 09:37:55 -0800 (PST) Received: from xps.lan (238.89-10-169.nextgentel.com. [89.10.169.238]) by smtp.gmail.com with ESMTPSA id v7sm1134696ljk.60.2021.01.16.09.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Jan 2021 09:37:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uged.al; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mxEgYGcQCZYKbRq3K2ngs08xWDWh3dTlzcMk23rneeQ=; b=ONxNoEUrPCGxB6M5IFJ2CYG1sWXTpgzhj4aK4aqkMTe61PAhVJloH06apvC5JWcFYn qQFHhWWe9VTPKnx28O/ZleRGHikVSkzCP+e4+/cYbbLnf/wy3ZZgp0f3ph6YvtxIEksu yYmJZTMSpIKT7RagJYoXr1jQ7gMgsYDnSC871szh7d8+3WYjo63Y7PSk4/NsSd3eau2C 7vGY5Y2VE/0E5rXhD9Mcklt2BcvPfgwNJR3jHrYwrfaS55ry0tWwzLm9/laqA1xawliJ E/XKgcnyO1OB4Nd0xu35HGQdMLTIj7k+176Ne6oy4IrSwgqxuTFyow9EZvABxykXEP16 uS4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mxEgYGcQCZYKbRq3K2ngs08xWDWh3dTlzcMk23rneeQ=; b=ptcg9MA0YW82bPw4dnTw0beM+en51g8p97rSdnbxipxPlkUmMeRiPW2eb9S5SmeOll WFFcU1qjY1UKmIzz2Mk1DhQcgQQ+b0ziDEusFXRKsdXrA8X0yIdW+lbdP8dFXFVlidyp kVWimO7Qt+KYwfp7+qYaIYId8m4I7rPLVNq/UWDbzmVaGFLqqU1KcC5EIcQBjIyy0y8j L+CNvyo98r16zriqURjZMD8i2SJHDuWwCVIyCbFtOVPZQnlBJ1mBHziolPLdFpmWAeeU eQoqlhi/yFXtMUBsPBSQgA2vrb7IXV6sOTGii0uqRdtcbLp/Ev1pW9bKr3M/+I7Tk1a/ uLHg== X-Gm-Message-State: AOAM531yYSmg5GN1YCwbmPioKTz8bahBtTMzumg3j93Es4XZ3KrGyn3W hNzq8bnUjvK8WYlA5cGVd5cl1g== X-Google-Smtp-Source: ABdhPJzZ2isHzSByM6U4LO4hvKLBiheZz/goKXIzhuOgnnX0KV/FV43e81LoAdS2DlMtgwtKZsxjLg== X-Received: by 2002:ac2:4431:: with SMTP id w17mr7598763lfl.223.1610818673989; Sat, 16 Jan 2021 09:37:53 -0800 (PST) From: Odin Ugedal Cc: tj@kernel.org, lizefan@huawei.com, hannes@cmpxchg.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, dschatzberg@fb.com, surenb@google.com, Odin Ugedal Subject: [PATCH v2 1/2] cgroup: fix psi monitor for root cgroup Date: Sat, 16 Jan 2021 18:36:33 +0100 Message-Id: <20210116173634.1615875-2-odin@uged.al> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210116173634.1615875-1-odin@uged.al> References: <20210116173634.1615875-1-odin@uged.al> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Fix NULL pointer dereference when adding new psi monitor to the root cgroup. PSI files for root cgroup was introduced in df5ba5be742 by using system wide psi struct when reading, but file write/monitor was not properly fixed. Since the PSI config for the root cgroup isn't initialized, the current implementation tries to lock a NULL ptr, resulting in a crash. Can be triggered by running this as root: $ tee /sys/fs/cgroup/cpu.pressure <<< "some 10000 1000000" Signed-off-by: Odin Ugedal Reviewed-by: Suren Baghdasaryan --- kernel/cgroup/cgroup.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 613845769103..1ea995f801ec 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3564,6 +3564,7 @@ static ssize_t cgroup_pressure_write(struct kernfs_op= en_file *of, char *buf, { struct psi_trigger *new; struct cgroup *cgrp; + struct psi_group *psi; =20 cgrp =3D cgroup_kn_lock_live(of->kn, false); if (!cgrp) @@ -3572,7 +3573,8 @@ static ssize_t cgroup_pressure_write(struct kernfs_op= en_file *of, char *buf, cgroup_get(cgrp); cgroup_kn_unlock(of->kn); =20 - new =3D psi_trigger_create(&cgrp->psi, buf, nbytes, res); + psi =3D cgroup_ino(cgrp) =3D=3D 1 ? &psi_system : &cgrp->psi; + new =3D psi_trigger_create(psi, buf, nbytes, res); if (IS_ERR(new)) { cgroup_put(cgrp); return PTR_ERR(new); --=20 2.30.0