Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp5107493pxb; Wed, 26 Jan 2022 05:06:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJwEm91DvanuGl7EJUaWZJuZttXuqwRICTuilKijRH7Sm/OjC6vHjYF6VkOg+M2a+KN/ghjE X-Received: by 2002:a17:906:9743:: with SMTP id o3mr20027840ejy.162.1643202362365; Wed, 26 Jan 2022 05:06:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643202362; cv=none; d=google.com; s=arc-20160816; b=Z3EY4lMef74XpDaoTbJKyxj2+G72uOnxpbAZEWpQQxQvb7ui27EKkxYklvnR4IwBMZ DKX3f88PwR6BxGNRwW2jedMo3PIbzpsza/aAUQtzD7tA6GyAS00tZegPkK4WIlPk1yDx gD9WzBobhGJPaxLXaEsCq8/7OYkxNa8auctGZaJWcjeEA4cJTVDAWyZdvNLlX9grL3SC 3lkTqCVp4NqwHOchQPtjnqEAvGJ+66DbO/P/tTQdH7r33sc/JoXnRLfupUyj5aoL4Ow/ ictWw2kh4STE3Y5wzn1oDtZMR841T3kyUhi3Ur1Tq+JgvKZGyfa347m8fk5Asqgiw4ax 9CYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=Nq/BEcfiGNa4aNbw2C/2NazcOp07pkLQ1tet6pMXlC4=; b=cMnrmY6JEFA0SUVS2ekhtQQIEW1bSEj8likHYkrSZ1A7JXKZxD5aiBqbkmonypb4XZ eQLFABoxA1cj/1so6NcF+fs5y4ZEv5kWguqU0O6rF0K1IHjYkUzHijxDo/+M6671T2Qa 0XwR3G3ZHSIoQibQ+t9LIoUb1a/RDmyc4I27ijTZcu6fBxEdW+xZXZniBuNNAhw0nopj LICO4PB1KHTHFinbhoG0Xzq1uJAstoE6jRuiY9FU8YcxqxHW7bTcsMAMU3v+HYJmvQ1m zPfehk0k/SW5E4sJLxEbExnXHPqPyFQWJmj8yem6n4ylkQ1btB1ZMxYYPwiWKohRoGCx oRaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bHeH3TlI; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m14si2927529edd.534.2022.01.26.05.05.36; Wed, 26 Jan 2022 05:06:02 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bHeH3TlI; 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=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234814AbiAYXbA (ORCPT + 99 others); Tue, 25 Jan 2022 18:31:00 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:42756 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234780AbiAYXa6 (ORCPT ); Tue, 25 Jan 2022 18:30:58 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 780D8612D6; Tue, 25 Jan 2022 23:30:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47102C340E0; Tue, 25 Jan 2022 23:30:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1643153457; bh=vB572nhmJuqCEgij4Dpji3wv3pIEvKb1pTOhhC//V2c=; h=Date:From:To:Cc:Subject:From; b=bHeH3TlIs6solJO243CJerwTfQLCEsu1sOHUOUVN8WYqvXoL6fuKosKa+BFp6hwIj Db/S2MS8lFNYcuGhjxvoZvDlIMZjIf4Wvg6fgQWyWuMBHm0voOktjco69X2L2hf7x6 BvQO2qVDYk0NuXbnrGSDt4QDvBkF7BbJ0U2zcRYYmJyuHgxestrUtm4nM2ZPhdGWcn qxWLMVfn2tGI+DJfupaqeeEmV2oZ2PMff/ibc4EUNld3Zp92126ALUhaVLto+K93Bb fO2qIHAtGiaqsPbZebrIgLkRGCFp2osK3GFRXShB/u5FnO8V7P7LxapLP5iBstGQ64 hksE/cEPiagaA== Date: Tue, 25 Jan 2022 17:37:44 -0600 From: "Gustavo A. R. Silva" To: Jiri Kosina , Benjamin Tissoires Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] HID: google: Use struct_size() helper in kzalloc() Message-ID: <20220125233744.GA81239@embeddedor> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 worst scenario, could lead to heap overflows. Also, address the following sparse warnings: drivers/hid/hid-google-hammer.c:61:23: warning: using sizeof on a flexible structure Link: https://github.com/KSPP/linux/issues/174 Signed-off-by: Gustavo A. R. Silva --- drivers/hid/hid-google-hammer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/hid/hid-google-hammer.c b/drivers/hid/hid-google-hammer.c index 0403beb3104b..ddbe0de177e2 100644 --- a/drivers/hid/hid-google-hammer.c +++ b/drivers/hid/hid-google-hammer.c @@ -58,7 +58,7 @@ static int cbas_ec_query_base(struct cros_ec_device *ec_dev, bool get_state, struct cros_ec_command *msg; int ret; - msg = kzalloc(sizeof(*msg) + max(sizeof(u32), sizeof(*params)), + msg = kzalloc(struct_size(msg, data, max(sizeof(u32), sizeof(*params))), GFP_KERNEL); if (!msg) return -ENOMEM; -- 2.27.0