Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp320250iob; Wed, 18 May 2022 02:59:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxEU6bjaylUcs5aoFbLrKjvo4Pmn/pnUlztJFUZEOHEVYPekL8CLfRo3m7tAJOCGhKqClFR X-Received: by 2002:a17:903:2343:b0:15e:9faa:e968 with SMTP id c3-20020a170903234300b0015e9faae968mr26739308plh.58.1652867982527; Wed, 18 May 2022 02:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652867982; cv=none; d=google.com; s=arc-20160816; b=bRzA9APX1bfWb5TX+AZ3aGQ/z9CEHiAByklGDW9YRxq/p5+clp1ik1sO3gWqk5+vhz NpHHX3DtFBsHzD0qzJjMiBvHfb2mvcB0eqdcbWwvXXCSq2ry7ZBtfiXAsj8lz8oymhog mF6uO/CVLwPfxRop46Oi29bNxTJxCD7NSzob6EWOj6jET2wOd62rx0wXLcAtYkXS7muX kAfqnInW2XoanaCiIR0oPmt05IKCot7xW5sx8b8pECyMOs29W2kVASfAwzngqqzqS9bE ckvTPRgwXRp2US83HJyu2oUq29lwK/AK6t2eGRZvv2w/wuxoyajJvUxWDNkdwZy80B5u 4OjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=LWp00f2tMZZgwY2TThJH+Faw3+NZ3AkZ3AiD8xJI62Y=; b=yV/pybzYQJLQbRNhG21fYlBHiYBMAPheZPfrjIh+TMGN/GZ6mzsLYz+hDhXt+5ly8X yyNudU1ONjbY9p7reuWpfl05DlBmmblSg10yzwdlpQqqYYeYfPHVMAFha5ZtMkCzaxEC eG8yq0u0i66w3307P21q/AXiI56ETqivTRJaKXtVBEF2/Tos+Rv8rhOv8+wiK0zWNthx FVwnBkLkoqzJ0CPYdAJr9vpFbouOo94OSBAH2MyT5ixuWOwjr546FFtXHQvzr6t1OexY RpEXAN70/H+YDpIrAgFX/7DVrMZrqK6n5FmNkMiK8ka2UGvt4Mzntw3GWXluOL01WnWa EHxw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id m1-20020a633f01000000b003db1c57226fsi1964264pga.741.2022.05.18.02.59.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 02:59:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2778E15352A; Wed, 18 May 2022 02:43:52 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234603AbiERJmp (ORCPT + 99 others); Wed, 18 May 2022 05:42:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234615AbiERJke (ORCPT ); Wed, 18 May 2022 05:40:34 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 984D714A27A; Wed, 18 May 2022 02:40:01 -0700 (PDT) Received: from canpemm500005.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4L37H213JpzhZHF; Wed, 18 May 2022 17:39:10 +0800 (CST) Received: from huawei.com (10.67.174.96) by canpemm500005.china.huawei.com (7.192.104.229) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Wed, 18 May 2022 17:39:59 +0800 From: Zhang Jianhua To: , CC: , Subject: [PATCH -next] fs-verity: Use struct_size() helper in fsverity_ioctl_measure() Date: Wed, 18 May 2022 17:38:29 +0800 Message-ID: <20220518093829.2248801-1-chris.zjh@huawei.com> X-Mailer: git-send-email 2.31.0 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.67.174.96] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500005.china.huawei.com (7.192.104.229) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 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: fs/verity/measure.c:48:9: warning: using sizeof on a flexible structure fs/verity/measure.c:52:38: warning: using sizeof on a flexible structure Signed-off-by: Zhang Jianhua --- fs/verity/measure.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/fs/verity/measure.c b/fs/verity/measure.c index e99c00350c28..4a388116d0de 100644 --- a/fs/verity/measure.c +++ b/fs/verity/measure.c @@ -27,6 +27,7 @@ int fsverity_ioctl_measure(struct file *filp, void __user *_uarg) const struct fsverity_info *vi; const struct fsverity_hash_alg *hash_alg; struct fsverity_digest arg; + size_t arg_size = struct_size(&arg, digest, 0); vi = fsverity_get_info(inode); if (!vi) @@ -44,11 +45,11 @@ int fsverity_ioctl_measure(struct file *filp, void __user *_uarg) if (arg.digest_size < hash_alg->digest_size) return -EOVERFLOW; - memset(&arg, 0, sizeof(arg)); + memset(&arg, 0, arg_size); arg.digest_algorithm = hash_alg - fsverity_hash_algs; arg.digest_size = hash_alg->digest_size; - if (copy_to_user(uarg, &arg, sizeof(arg))) + if (copy_to_user(uarg, &arg, arg_size)) return -EFAULT; if (copy_to_user(uarg->digest, vi->file_digest, hash_alg->digest_size)) -- 2.31.0