Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp75152pxb; Tue, 14 Sep 2021 19:07:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxa4+GrWtCgIqXGPoUt9ViADZJWv+md8CsKrenLvi12Gd9ATwXcMBv+SSNKTne7iLpL5nv8 X-Received: by 2002:a05:651c:1126:: with SMTP id e6mr18217859ljo.28.1631671634217; Tue, 14 Sep 2021 19:07:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631671634; cv=none; d=google.com; s=arc-20160816; b=ht4A2hu/ENLEcO8wSiDR+JmER5OWkAntlLYkEcJ/57cmUFJKLz0RsdMr3EyYJ9OsA2 OikJw4PApfN98d2+Z44+1/RDo0Pw2qLPuTLX/jCwdSj3dOi8MQjfLPaZuxdUi+H9WY1s 3DOqBTgE2OsYnfjLTjBScwdiEgrzI3H1eG1HWp687xmirYfwpRUa4U1z8ixYokxwDx0C q886/kjv9MDMnyePQZCwSop37EnluuwpDPnkmykS1L+u3xhaCym8wjxXzKvt08r/H/bD C2jCOuqiOkRsKHpYxn4CdWaL+QqyZ7inKVMq29q+pnDnxn1F1qdjfWbaMxkJ8VwMRvvS IqGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=gwgNfJliDAO3npOa165vt6HHwfN+elE4n8G47ERZMAk=; b=gJIcwfzzsoL7hXDXYGHVzQRQ8JcOeAyDOKwOV0JkjUsCbile673GqOhEJ1kX/jlyU6 EFCMh90lrOnLOzLEsxGF/WlvI0Q7y0iGEWDDUoMuTBM9/D0X0V6+Rmzsiz0erjZawv8H gptgx+aKIcotL1PEquup4BhGv8Vs5KHIzRa4kTj8H5qWcdtROnZkLKrArPrkOeYeDTSE tBtfAixiJL+A5P59icPEYPKnuI5vQ574PI4e7+E7YxnbMDD2AF3HIHELD8VFe9Z/UHix TLl7BQjqo+92rUAwxwoMX5A48U8XG9AmgbgS1sYZ33Khl9RnRACbEsAcPk93KBWZOMXP SVYQ== 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=NONE sp=NONE 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 t8si15626236ljd.623.2021.09.14.19.06.45; Tue, 14 Sep 2021 19:07:14 -0700 (PDT) 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=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232749AbhIOCFG (ORCPT + 99 others); Tue, 14 Sep 2021 22:05:06 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:9870 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231979AbhIOCFG (ORCPT ); Tue, 14 Sep 2021 22:05:06 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H8NgW5h64z8yXP; Wed, 15 Sep 2021 09:59:19 +0800 (CST) Received: from dggpemm500004.china.huawei.com (7.185.36.219) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 15 Sep 2021 10:03:46 +0800 Received: from [10.174.177.91] (10.174.177.91) by dggpemm500004.china.huawei.com (7.185.36.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.8; Wed, 15 Sep 2021 10:03:45 +0800 Subject: Re: [PATCH -next] irqdomain: fix overflow error To: Thomas Gleixner , CC: , References: <20210908014623.61357-1-cuibixuan@huawei.com> <87o88vcqvh.ffs@tglx> From: Bixuan Cui Message-ID: <4f614b66-ad85-7fa3-6e6e-2a672e8148e3@huawei.com> Date: Wed, 15 Sep 2021 10:03:44 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <87o88vcqvh.ffs@tglx> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.91] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500004.china.huawei.com (7.185.36.219) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/9/14 19:56, Thomas Gleixner wrote: > On Wed, Sep 08 2021 at 09:46, Bixuan Cui wrote: >> In function ‘kmalloc_node’, >> inlined from ‘kzalloc_node.constprop’ at ./include/linux/slab.h:743:9, >> inlined from ‘__irq_domain_add’ at kernel/irq/irqdomain.c:153:9: >> ./include/linux/slab.h:618:9: error: argument 1 value ‘18446744073709551615’ exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=] >> return __kmalloc_node(size, flags, node); >> >> The 'size' can be negative here, which will then get turned into a giant >> size argument for kzalloc_node(). Changing the size to 'unsigned int' >> instead seems more appropriate. > What's more appropriate about that? We call struct_size(domain, revmap, size) in __irq_domain_add() for calculations. The struct_size() is implemented in include/linux/overflow.h static inline __must_check size_t __ab_c_size(size_t a, size_t b, size_t c) { size_t bytes; The 'size' is passed to __ab_c_size(), the input parameter is 'size_t'(unsigned int). On the other hand, I looked at all the code that calls __irq_domain_add(), such as: include/linux/irqdomain.h: static inline struct irq_domain *irq_domain_create_linear(struct fwnode_handle *fwnode, unsigned int size, const struct irq_domain_ops *ops, void *host_data) { return __irq_domain_add(fwnode, size, size, 0, ops, host_data); or static inline struct irq_domain *irq_domain_add_linear(struct device_node *of_node, unsigned int size, const struct irq_domain_ops *ops, void *host_data) { return __irq_domain_add(of_node_to_fwnode(of_node), size, size, 0, ops, host_data); And kernel/irq/irqdomain.c struct irq_domain *irq_domain_create_simple(struct fwnode_handle *fwnode, unsigned int size, unsigned int first_irq, const struct irq_domain_ops *ops, void *host_data) { struct irq_domain *domain; domain = __irq_domain_add(fwnode, size, size, 0, ops, host_data); All 'size' passed to __irq_domain_add() are unsigned int. So I think it's more appropriate to replace it with unsigned int. Thanks, Bixuan Cui