From patchwork Mon Mar 22 16:02:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 406162 Delivered-To: patch@linaro.org Received: by 2002:a17:906:5290:0:0:0:0 with SMTP id c16csp1347723ejm; Mon, 22 Mar 2021 09:04:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxomW27j00I84Dm4y7Ig6Oph85WmXUhkgCOxLlL1nvJqQH7O+25UAk9ya/iGsaOhbXdbyar X-Received: by 2002:a17:902:59c9:b029:e6:5cdd:f709 with SMTP id d9-20020a17090259c9b02900e65cddf709mr360358plj.20.1616429079984; Mon, 22 Mar 2021 09:04:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616429079; cv=none; d=google.com; s=arc-20160816; b=WCox7uSh94O3xWTR+ImdbTf2Ak/sVIu6v7kioWRUaDwx6Ybf58QrBBUZNiF5ZS9NCm LBrFfvrlK4R2+QtZzhngdU4BEC+J4d5iI1R40ep4zoOVihWYbyrpBO6p0/7JVPNzKQbt n+pzUW04QA1527vAdnaZpu99ABl/Js/+P7J+1kZZJdS6tKceSqmwzrG9CpwMwoT582HU 8G64Kkiqo++8QI8+aao0mksZDCHKdLxSmJMlqEC3C3Q5PzZfePoIGMSafT3uGmzEfQtF 6ite/RPXcGNlYThtXJ69XrnjflWZRvQYBSF2+hRyuXJxACexgWY3MRMwy1DeTkNYfgdL mjhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:delivered-to; bh=9wlApGGlxLKV8Z1QtRWqh8SahBtlv/0k3KyVAtCmAB4=; b=p+JNgBAb9sN9/JmBtYb7T+sBYPYFDZ3ZoWGfiYOBw562I6IFSUvaz9Om/iLD+boXGh N3Lm7GkmN4mup7/s11fVukmkmQZjU54+7oYRGSAYxKMppvcC2GFQd2PbvWMC6lxm2TAh +nyx19pjF0c06mOsiZmA+y9+PjnCDLN5boaMnUiR4q+Vh9oD2S2AZJzmoUrQ0nVq1yQ9 Cv+TR8y/DvudusihHqfYMxY57CREpKviDdmltefvb1WQ/pvBo4Ij6RlPnfGPZPBTMgnF w/DCH+bMrsh6ShR7TAphg41piih96empBzb2Yp0dE5VbjYi/0Ygs5B1PAKbB4LZXbPeT oOtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=UB5shkw7; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id k2si14887560plk.371.2021.03.22.09.04.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Mar 2021 09:04:39 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@kernel.org header.s=k20201202 header.b=UB5shkw7; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ED4DC6E500; Mon, 22 Mar 2021 16:04:38 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by gabe.freedesktop.org (Postfix) with ESMTPS id BE0406E500; Mon, 22 Mar 2021 16:04:37 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id DD9F06199F; Mon, 22 Mar 2021 16:04:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1616429077; bh=yAy/I3E6cDxsmlVnV0YJAH5ZEQIRtNmu4zak4TbdMtM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UB5shkw7Yd4R5EAaTaJbKCgGMQHdzM6i80uoGxhNLAKr58/Z+hb/X02iDZFbFM5q7 ohBr0mnuKE2zD2dZIPp5mGV/8upXxQjJIfPGJp9PdMs6uae5VNAC7zYBRMfKWnHX2T dVcWKQocYTTmbDcT2P/QpYMSgUNzpEBC5mOFpZCLPDNYvMuLPWfLzgAFpKC9vWx2UV WcW6Gm/cjDbzo+bVOJsKrlf8DWJ6XKsV5KO6yCyvx8yAazXnd03HJIpEKsAL1WBIyL rctKK7FEjfv0XP7F/8O3bxyOq6H75TM+jdZPPW1bjsoXOWVbf0YQRUVNLoyOj2UQzP uTGmECN+tjDoA== From: Arnd Bergmann To: linux-kernel@vger.kernel.org, Martin Sebor , Tejun Heo , Zefan Li , Johannes Weiner Subject: [PATCH 06/11] cgroup: fix -Wzero-length-bounds warnings Date: Mon, 22 Mar 2021 17:02:44 +0100 Message-Id: <20210322160253.4032422-7-arnd@kernel.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210322160253.4032422-1-arnd@kernel.org> References: <20210322160253.4032422-1-arnd@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexei Starovoitov , dri-devel@lists.freedesktop.org, Cong Wang , Christian Brauner , Odin Ugedal , linux-scsi@vger.kernel.org, x86@kernel.org, James Smart , tboot-devel@lists.sourceforge.net, Kalle Valo , Andrii Nakryiko , ath11k@lists.infradead.org, Serge Hallyn , Arnd Bergmann , "James E.J. Bottomley" , Ning Sun , Anders Larsen , Bhaskar Chowdhury , cgroups@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-wireless@vger.kernel.org, linux-security-module@vger.kernel.org, =?utf-8?q?Michal_Koutn=C3=BD?= , Simon Kelley , intel-gfx@lists.freedesktop.org, Roman Gushchin Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Arnd Bergmann When cgroups are enabled, but every single subsystem is turned off, CGROUP_SUBSYS_COUNT is zero, and the cgrp->subsys[] array has no members. gcc-11 points out that this leads to an invalid access in any function that might access this array: kernel/cgroup/cgroup.c: In function 'cgroup_addrm_files': kernel/cgroup/cgroup.c:460:58: warning: array subscript '' is outside the bounds of an interior zero-length array 'struct cgroup_subsys_state *[0]' [-Wzero-length-bounds] kernel/cgroup/cgroup.c:460:24: note: in expansion of macro 'rcu_dereference_check' 460 | return rcu_dereference_check(cgrp->subsys[ss->id], | ^~~~~~~~~~~~~~~~~~~~~ In file included from include/linux/cgroup.h:28, from kernel/cgroup/cgroup-internal.h:5, from kernel/cgroup/cgroup.c:31: include/linux/cgroup-defs.h:422:43: note: while referencing 'subsys' 422 | struct cgroup_subsys_state __rcu *subsys[CGROUP_SUBSYS_COUNT]; I'm not sure what is expected to happen for such a configuration, presumably these functions are never calls in that case. Adding a sanity check in each function we get the warning for manages to shut up the warnings and do nothing instead. Signed-off-by: Arnd Bergmann --- I'm grouping this together with the -Wstringop-overread warnings, since the underlying logic in gcc seems to be the same. --- kernel/cgroup/cgroup.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) -- 2.29.2 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 9153b20e5cc6..3477f1dc7872 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -456,7 +456,7 @@ static u16 cgroup_ss_mask(struct cgroup *cgrp) static struct cgroup_subsys_state *cgroup_css(struct cgroup *cgrp, struct cgroup_subsys *ss) { - if (ss) + if (ss && (CGROUP_SUBSYS_COUNT > 0)) return rcu_dereference_check(cgrp->subsys[ss->id], lockdep_is_held(&cgroup_mutex)); else @@ -534,6 +534,9 @@ struct cgroup_subsys_state *cgroup_e_css(struct cgroup *cgrp, { struct cgroup_subsys_state *css; + if (CGROUP_SUBSYS_COUNT == 0) + return NULL; + do { css = cgroup_css(cgrp, ss); @@ -561,6 +564,9 @@ struct cgroup_subsys_state *cgroup_get_e_css(struct cgroup *cgrp, { struct cgroup_subsys_state *css; + if (CGROUP_SUBSYS_COUNT == 0) + return NULL; + rcu_read_lock(); do { @@ -630,7 +636,7 @@ struct cgroup_subsys_state *of_css(struct kernfs_open_file *of) * the matching css from the cgroup's subsys table is guaranteed to * be and stay valid until the enclosing operation is complete. */ - if (cft->ss) + if (cft->ss && CGROUP_SUBSYS_COUNT > 0) return rcu_dereference_raw(cgrp->subsys[cft->ss->id]); else return &cgrp->self; @@ -2343,6 +2349,9 @@ struct task_struct *cgroup_taskset_next(struct cgroup_taskset *tset, struct css_set *cset = tset->cur_cset; struct task_struct *task = tset->cur_task; + if (CGROUP_SUBSYS_COUNT == 0) + return NULL; + while (&cset->mg_node != tset->csets) { if (!task) task = list_first_entry(&cset->mg_tasks, @@ -4523,7 +4532,7 @@ void css_task_iter_start(struct cgroup_subsys_state *css, unsigned int flags, it->ss = css->ss; it->flags = flags; - if (it->ss) + if (it->ss && CGROUP_SUBSYS_COUNT > 0) it->cset_pos = &css->cgroup->e_csets[css->ss->id]; else it->cset_pos = &css->cgroup->cset_links;