From patchwork Thu Jun 22 23:25:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Gustavo A. R. Silva" X-Patchwork-Id: 111853 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp5427177vqr; Thu, 22 Jun 2023 17:13:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ69V7IhAP3tMizIETiqzNKWoze+n7fG23Cnb+Dzu/InRPWmzEA3QQnigk7W4Hkj82bb5l8i X-Received: by 2002:a05:6a20:1596:b0:10c:663c:31c3 with SMTP id h22-20020a056a20159600b0010c663c31c3mr19284855pzj.29.1687479239530; Thu, 22 Jun 2023 17:13:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687479239; cv=none; d=google.com; s=arc-20160816; b=S8Jq9qPBgIln9rdYs8g4AjDr3344/z32KOJuCR+zNgpmn5pv+U03IebliBKc1hvoUp U2UQKDpFEugTNc2h14J1Pzub5r+3A5dj9UOesE9kyB7F4lLWEl4KaU2aYm/mVWlFgbho ihMqt6mHMZ/rZRLb7zhqSRzOHrNVgbgi6BcMnOtdInh4PVkRaElxe9hZkMRcMigi2+fP +TRtFyM28+tBzzd0T0ftWKJ/s7X03J4vERkhonM2l4nriNVly14ikVMjz5c+Zni+aF2I ztBnCRNAP+XgeBJHovVMEqUBDdQTBxSjbtRboVPzRqd+2MYnttOPx9x9DXZK8N7YU22L 6ChQ== 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=C+hqcmy79jOV5+tpD2pKd8A26uYZNOvu63l0/zJFtxk=; b=WfG/MEWerVbArEJ2R3hB9wTfHeJCfeC28aNBhUt+8gp8te170Ny93mXjYc99gjruJz 9U1gtA6y3yTnUM0AAevdzmSNRMnt5f+HHmy7AixinMXhAbQO5O9JPWvRhZuxBaeuVb6t 6XBzeE8gQZMEkoiJyqd3rZgLGnCeNjU17GCRbD3f1AkHN9reNG8PItlJ15O0g4CG/qgT Fa6/Jma4pzxtqnciomDVTO2ssorHZVXU+C+W+e1f/wLPHyV5HD0oeNpkRWgtI20I/don hwiIxrTWhwjlIE1HyTFHpbFhZctlF79xE27kF8ZkNr2CbSMlNPUYcXeD9Qr3AU0Tuo1i 6NOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W3NOkPNs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n17-20020a170902d2d100b001a6b6085041si8557329plc.512.2023.06.22.17.13.40; Thu, 22 Jun 2023 17:13:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=W3NOkPNs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231512AbjFVXYW (ORCPT + 99 others); Thu, 22 Jun 2023 19:24:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231368AbjFVXYU (ORCPT ); Thu, 22 Jun 2023 19:24:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59F331992; Thu, 22 Jun 2023 16:24:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E647D61710; Thu, 22 Jun 2023 23:24:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1527C433C0; Thu, 22 Jun 2023 23:24:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1687476258; bh=9l3yT4c7WDuIVAHRSLpHtSAsORZMZ/UnIYSe9gs3Uow=; h=Date:From:To:Cc:Subject:From; b=W3NOkPNsCMY+YwGljyypyg75v94Gd2jlwQfDRAS9jcgmYQQlUoUeVbWsmlPGOZ3UQ Vb9jtdUeL+kCqJ3pZYs+8KHmTNU2OlvmwZvYUbv4cZicZUlfFhn7FV/e5m4BxzHzWg OT/Klv8LrZSZ9Gum4BtI6hwSyAUcrL3Ik94sPqBRigmjRTVKrOnOnz8Vc1AnNKYskR KhoemsdFBkaQpFjUmjTFb1QHdlMfjgf0fjmgR5x/I2RUJoRgS1gomvl74z6NJ/Ok3e TsjCVhJenROERDFCwPkBYqfubrI5ePd6yHpF0eKp6CTsQL/S1pYG73GXByeI9sRESq sMNwO3i9iDXRg== Date: Thu, 22 Jun 2023 17:25:13 -0600 From: "Gustavo A. R. Silva" To: "David S. Miller" Cc: sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org, "Gustavo A. R. Silva" , linux-hardening@vger.kernel.org Subject: [PATCH][next] openprom: Use struct_size() helper Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769450231085209603?= X-GMAIL-MSGID: =?utf-8?q?1769450231085209603?= Prefer struct_size() over open-coded versions. Link: https://github.com/KSPP/linux/issues/160 Signed-off-by: Gustavo A. R. Silva Reviewed-by: Kees Cook --- drivers/sbus/char/openprom.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/sbus/char/openprom.c b/drivers/sbus/char/openprom.c index 30b9751aad30..de56c8fec373 100644 --- a/drivers/sbus/char/openprom.c +++ b/drivers/sbus/char/openprom.c @@ -76,7 +76,9 @@ static int copyin(struct openpromio __user *info, struct openpromio **opp_p) if (bufsize > OPROMMAXPARAM) bufsize = OPROMMAXPARAM; - if (!(*opp_p = kzalloc(sizeof(int) + bufsize + 1, GFP_KERNEL))) + *opp_p = kzalloc(struct_size(*opp_p, oprom_array, bufsize + 1), + GFP_KERNEL); + if (!*opp_p) return -ENOMEM; if (copy_from_user(&(*opp_p)->oprom_array, @@ -95,7 +97,9 @@ static int getstrings(struct openpromio __user *info, struct openpromio **opp_p) if (!info || !opp_p) return -EFAULT; - if (!(*opp_p = kzalloc(sizeof(int) + OPROMMAXPARAM + 1, GFP_KERNEL))) + *opp_p = kzalloc(struct_size(*opp_p, oprom_array, OPROMMAXPARAM + 1), + GFP_KERNEL); + if (!*opp_p) return -ENOMEM; (*opp_p)->oprom_size = 0;