Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3383499pxb; Mon, 17 Jan 2022 19:12:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJxuB5jCjWBuY7HPsuO1L95uz13U7ELBkjBWgNMGoIvvtZvf9pTd07qwDLpTv42dQE312bIv X-Received: by 2002:a62:cd02:0:b0:4bd:8f59:dc4e with SMTP id o2-20020a62cd02000000b004bd8f59dc4emr24105565pfg.64.1642475555070; Mon, 17 Jan 2022 19:12:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642475555; cv=none; d=google.com; s=arc-20160816; b=qGPxbD1es8Na1oJucYe6D2pYbfm1Udf1EQSQnVzeyTHokgk/Q6U4ZTWKagaxu2NAIJ k+Pr4Dg9ScPiCuoQrlpdqLgIKBI6aFsJvrTpo4Kt91IlmBYurU8z9VpYqsoGmLnV+n/a oaLZ5C3sgLcZ6GdUWjYJvYpbBtTmsV+TIgNpEPFcIYkrW3vUFMQokruIhicEztlkb656 Oz9tMC7oxuYb3CUz26FMEEWUqmFThu7J7iuo3oJpNS8FOi8VgRM4vUxfdl/u++EYy/d/ I1m0WiH2Gd0pj/4vBDOWWKG1zG01yh9eQKgEY+poPqELNevl+m8YLSUD/3GC6n9YnT4i Hayg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:subject:cc:to:from; bh=vN2lTgEFFaMZS+P8Q8BaMK/iat9fVOrZAhdSuRoJpio=; b=A3H5o88mUwL8H4idcCJdJ4PY346S7AGO3e1aydlBD1vs9cQqduBl0Tl0zkE62mw6VY zFPBzbLiYnYfV2e1er3Hm6aePCZKZ26V6mkgTQpi+e/2Bbuk4xooYXYWbBKrejJjpb/7 JOFftWrntDLyZvP9VVaFiLbbNiJOFHn4RLEQWNSPwPwo0TUynctSLYGffsN8DajCpwD0 PmJJrF3ynqERn2PS9FwklaLqsocU8XdXZ4n7A7VPTmuZ5BVxuIOtY/XjcSkppJWRftLx qBPvDOUlHe9QXEqM8pr6Urx2qfSooBahRqIQlShTByiSuJyA0eGD2YsQk6ynr8mGSndj Lvpg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z19si1652987pgj.111.2022.01.17.19.12.22; Mon, 17 Jan 2022 19:12:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244431AbiARBjw (ORCPT + 99 others); Mon, 17 Jan 2022 20:39:52 -0500 Received: from szxga01-in.huawei.com ([45.249.212.187]:16719 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244464AbiARBjL (ORCPT ); Mon, 17 Jan 2022 20:39:11 -0500 Received: from dggpeml500023.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JdBDG1mSTzZcw4; Tue, 18 Jan 2022 09:35:26 +0800 (CST) Received: from ubuntu1804.huawei.com (10.67.174.58) by dggpeml500023.china.huawei.com (7.185.36.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Tue, 18 Jan 2022 09:39:09 +0800 From: Xiu Jianfeng To: , , , , , , , , , CC: , Subject: [PATCH -next, v3] sched: Use struct_size() helper in task_numa_group() Date: Tue, 18 Jan 2022 09:39:37 +0800 Message-ID: <20220118013937.129318-1-xiujianfeng@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.174.58] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500023.china.huawei.com (7.185.36.114) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Make use of the struct_size() helper instead of an open-coded version, in order to avoid any potential type mistakes or integer overflows that, in the worse scenario, could lead to heap overflows. Link: https://github.com/KSPP/linux/issues/160 Signed-off-by: Xiu Jianfeng --- kernel/sched/fair.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c index 095b0aa378df..1a21bb33a4b2 100644 --- a/kernel/sched/fair.c +++ b/kernel/sched/fair.c @@ -2437,9 +2437,8 @@ static void task_numa_group(struct task_struct *p, int cpupid, int flags, int i; if (unlikely(!deref_curr_numa_group(p))) { - unsigned int size = sizeof(struct numa_group) + - NR_NUMA_HINT_FAULT_STATS * - nr_node_ids * sizeof(unsigned long); + size_t size = struct_size(grp, faults, + NR_NUMA_HINT_FAULT_STATS * nr_node_ids); grp = kzalloc(size, GFP_KERNEL | __GFP_NOWARN); if (!grp) -- 2.17.1