Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2018967pxa; Fri, 7 Aug 2020 00:31:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKWTmCE3ZoN+5+0hqHGz5BWFinKNjltRwIKBH2PM7jZxUv2t2bFTNM8ZmIWhlVnbc1CkPv X-Received: by 2002:a17:907:11d0:: with SMTP id va16mr8437741ejb.426.1596785517745; Fri, 07 Aug 2020 00:31:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596785517; cv=none; d=google.com; s=arc-20160816; b=Gmb+SFjrwM4rloD7FRliY/0YorJETYrVyy16/n3XzwSy3XBbYAq04XR1CtiM7HYgK+ 2WRViKlrpYkj8WbgxGxiDGysGr7Axn8+nMjflKIfOu3tR5K23ObdIa0gSc3KyOOAQ1Dw wI+oSJNkHMOF940HU7cA8uvIYPlA7ByTXNyqYFVBmwYhkKF2vBi4ij7R/KlN2HDZuWLb OANczguBd2Xr8nz3zrbzpTSDVw9QiaLDNxZr7SKoNulHUk10gT+9EPRH6EolCEWCkiNv dTPycFPTeIpWUEpNUVOYwhTQO2qX9hgOJyM86Pqnie0psssgz83QDxDatsW4gQgakNoF ubNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=12q2iDN/YQAMmiwijXrl91ogiPtfmiW0SAQOocLHo1Y=; b=E1fNVG9MyAQa9EnNfqBGkoe1GKWZ/lLjbHQNNxEa1ec6xEpu6FTwierxNg65jDbVi2 LdvRsQUpY8/AqhxESRoUdNI+pBAJrz9rue+21izEpevo102fK2IK/T5K63tJuIj+dMoC xv9aQk9BFhlyWn0LIBJifnRcYxKCveGMIZhJXxDITuJxzZ/it9JY3JwAo6qB/p59m3py Gv/GNOSiMScg1seN+vT9Zi4eukF7/emfa18cUG9Ih6dQnXwkslfZ1zw0YG5bEEfPtwtP wM3oVDtcVypOCKse6OQmQXXUzfVZwBiw+RlHLPVbjDJk8rve/ZDKWfVZIgY84j2FJgua 4ynw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PgDuZ1Ao; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id de7si5172748edb.278.2020.08.07.00.31.34; Fri, 07 Aug 2020 00:31:57 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PgDuZ1Ao; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726776AbgHGHa5 (ORCPT + 99 others); Fri, 7 Aug 2020 03:30:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726038AbgHGHa4 (ORCPT ); Fri, 7 Aug 2020 03:30:56 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15581C061574; Fri, 7 Aug 2020 00:30:56 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id u20so562975pfn.0; Fri, 07 Aug 2020 00:30:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=12q2iDN/YQAMmiwijXrl91ogiPtfmiW0SAQOocLHo1Y=; b=PgDuZ1AoFYFz62izIwb8cPWickw2zyUdR0fekCVZjn9rmvwp1dzA8gYt15mXy/X4nO MfNUI/+cBcpKSP4nPLppo4NFz3iFo1r1mqopO+rcJe5qBu4AYJLOPEiHgi/gnJgC4YEN 5NyPkQysnkUJIaIpEXqjE6VhRgc79RaVwtW2JtDMDKlxsemMhm6jsKNhHMCNwKBIGdBK S4OxKHs9oXOcnl9lJ3g87nJK/NmOfy8390CCCP8twbF/8NTkzGtGZSsEYrkiGCqi7R7/ y6RBUOlERLfa1CPuuRmdVsPOzez4He2s75v6O2IgMZjwWtUjqxAhDlx3MCKozp0qEzNG /PVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=12q2iDN/YQAMmiwijXrl91ogiPtfmiW0SAQOocLHo1Y=; b=ShEtwcTTzeiKCMvJ/V6xTcY0LjgI43Z81DDmKcdDLfe7qp1HSq0D/CLOLNv89u1VcW OHG/2RrvyICdJVkAsqVyEjkapiUigFTLfah3+T9qQi5E1WsppeJQmRWjkMN+W61I6o4c BcuW/c7hfgfkWWe9GrxqG16Y7U0xdubeCInmVAJo0leYkDKR8slaXwPyONEsYasKnTcz Ha80lxMajwXZ0scmxktWQ0U4/3kKN/q2lfetoqW1zhxC8NPJkUeiyekSmqSnwXTq+uIa 3o6OYzC+eomr6l+chRQqCsIme83+frpNZ2t3D7TVOKoetWg3AUuhqalVt53ywbrZPS/x 3Fuw== X-Gm-Message-State: AOAM530+FXS3WOFMW8JUx8MRdgn0Y4pulApRT5AQfcmUAnVN4oKGJJXb yRR4xui4Ia2KOgIYW82/tHE= X-Received: by 2002:a62:1543:: with SMTP id 64mr12301411pfv.242.1596785455446; Fri, 07 Aug 2020 00:30:55 -0700 (PDT) Received: from dc803.localdomain (FL1-218-42-16-224.hyg.mesh.ad.jp. [218.42.16.224]) by smtp.gmail.com with ESMTPSA id y7sm10020079pjm.3.2020.08.07.00.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 07 Aug 2020 00:30:55 -0700 (PDT) From: Tetsuhiro Kohada To: kohada.t2@gmail.com Cc: kohada.tetsuhiro@dc.mitsubishielectric.co.jp, mori.takahiro@ab.mitsubishielectric.co.jp, motai.hirotaka@aj.mitsubishielectric.co.jp, Namjae Jeon , Sungjong Seo , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] exfat: add dir-entry set checksum validation Date: Fri, 7 Aug 2020 16:30:48 +0900 Message-Id: <20200807073049.24959-1-kohada.t2@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add checksum validation for dir-entry set when getting it. exfat_calc_dir_chksum_with_entry_set() also validates entry-type. ** This patch depends on: '[PATCH v3] exfat: integrates dir-entry getting and validation' Signed-off-by: Tetsuhiro Kohada --- fs/exfat/dir.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/fs/exfat/dir.c b/fs/exfat/dir.c index c9715c7a55a1..2e79ac464f5f 100644 --- a/fs/exfat/dir.c +++ b/fs/exfat/dir.c @@ -563,18 +563,27 @@ int exfat_remove_entries(struct inode *inode, struct exfat_chain *p_dir, return 0; } -void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es) +static int exfat_calc_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es, u16 *chksum) { - int chksum_type = CS_DIR_ENTRY, i; - unsigned short chksum = 0; struct exfat_dentry *ep; + int i; - for (i = 0; i < es->num_entries; i++) { - ep = exfat_get_validated_dentry(es, i, TYPE_ALL); - chksum = exfat_calc_chksum16(ep, DENTRY_SIZE, chksum, - chksum_type); - chksum_type = CS_DEFAULT; + ep = container_of(es->de_file, struct exfat_dentry, dentry.file); + *chksum = exfat_calc_chksum16(ep, DENTRY_SIZE, 0, CS_DIR_ENTRY); + for (i = 0; i < es->de_file->num_ext; i++) { + ep = exfat_get_validated_dentry(es, 1 + i, TYPE_SECONDARY); + if (!ep) + return -EIO; + *chksum = exfat_calc_chksum16(ep, DENTRY_SIZE, *chksum, CS_DEFAULT); } + return 0; +} + +void exfat_update_dir_chksum_with_entry_set(struct exfat_entry_set_cache *es) +{ + u16 chksum; + + exfat_calc_dir_chksum_with_entry_set(es, &chksum); es->de_file->checksum = cpu_to_le16(chksum); es->modified = true; } @@ -775,6 +784,7 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb, struct exfat_entry_set_cache *es; struct exfat_dentry *ep; struct buffer_head *bh; + u16 chksum; if (p_dir->dir == DIR_DELETED) { exfat_err(sb, "access to deleted dentry"); @@ -839,10 +849,10 @@ struct exfat_entry_set_cache *exfat_get_dentry_set(struct super_block *sb, goto free_es; es->de_stream = &ep->dentry.stream; - for (i = 2; i < es->num_entries; i++) { - if (!exfat_get_validated_dentry(es, i, TYPE_SECONDARY)) - goto free_es; - } + if (max_entries == ES_ALL_ENTRIES && + ((exfat_calc_dir_chksum_with_entry_set(es, &chksum) || + chksum != le16_to_cpu(es->de_file->checksum)))) + goto free_es; return es; -- 2.25.1