Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp433188ybg; Mon, 1 Jun 2020 05:23:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJychJpD5PlTJC/nWvl2i2/qP5HDX20k8YPk/R1WZRuClvkqEFveWEsn+N1wvfgBf1rdNPmo X-Received: by 2002:a17:906:19c7:: with SMTP id h7mr4440075ejd.403.1591014219459; Mon, 01 Jun 2020 05:23:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591014219; cv=none; d=google.com; s=arc-20160816; b=VQidDEzd9WXL7E6s2qCRq3vue2rWgQPUFIsPvCE8bIbEbBxZqW39yo1YhixNNL7mUS c1ozqMczEHBbq8VmwiHVIvvPoZvBEZbLZcNZUTKL12/dqmXAffvWG+IhFOQ3dkSH3vxX k5IeIx+YSw8gG+o5GQzkc9hvE1D07y/Gm5tKbUmjAwQuEMHHXIgnG4GdWYgzUPxpIR+8 Vhd90I9yWwMTb0Cj5VrA1rEt2do3zW0a+fRMgbg/E+BmePX42JoGA1kjS1VO38HPXCSG 11ot2lbvoBfpzBN2JNVcrNyFbR1+o4hWtmNU5hpT8VTPS+kwHyMFrUerWQ3zrutoQXgo dZjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:dlp-filter:cms-type :content-language:thread-index:content-transfer-encoding :mime-version:message-id:date:subject:in-reply-to:cc:to:from :dkim-signature:dkim-filter; bh=cR8G8UhJZH1vpmm89wdfJzNuLbJHxWQnLT4AHHIGFhw=; b=qSWknJ6SyJhdxQ2Mlq+pC+rKwN60hZ9OfggB//xyTsrws9cTJP6x7U0/jXlg9JMWQs XCmgG35cZs2DWBZuP9PwhYxGsrEWbzqdDjlzwTPdQAc/nS59Y+Wpd1+fDSMDcQEixdrk SV01wrRQtU7Yln5M5hN0T+l1LJnZ8ifSSBR5l9JVb1/nfB2T+OCpLfz2tD7r2UTlQtO8 jeqD2AgO6A8G4uRqa3WEcpJxj4EDjhQ238/S4dTpHFwJpszK+f/qNXmvISrU6uGVSiB+ Wgkgqdi6SXJyUw1rbW2sbATbr8vrf838RJ9zF7zCSHAIM7DaXVPKVcX0yWbL7n3tJZ4E lvhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=LVc2NgNn; 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=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d5si10890385edy.123.2020.06.01.05.23.16; Mon, 01 Jun 2020 05:23:39 -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=@samsung.com header.s=mail20170921 header.b=LVc2NgNn; 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=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726089AbgFAMVZ (ORCPT + 99 others); Mon, 1 Jun 2020 08:21:25 -0400 Received: from mailout2.samsung.com ([203.254.224.25]:30429 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725838AbgFAMVY (ORCPT ); Mon, 1 Jun 2020 08:21:24 -0400 Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20200601122119epoutp028502c9efabd525e99ee4d8224ad254f4~UauA2KE8I0885508855epoutp02G for ; Mon, 1 Jun 2020 12:21:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20200601122119epoutp028502c9efabd525e99ee4d8224ad254f4~UauA2KE8I0885508855epoutp02G DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1591014079; bh=cR8G8UhJZH1vpmm89wdfJzNuLbJHxWQnLT4AHHIGFhw=; h=From:To:Cc:In-Reply-To:Subject:Date:References:From; b=LVc2NgNnJdMb4MuMac3Ozw7e7DmXyLwN8at65NswqyG6psTqn5opog18bXH19+pPy HMWR9g8TwehaNCczreHaeya9ZNirD9S1gF0T+If7v/9U0YDfybyShepnFwcLr0w+Xn RwqMdowwSTHpk5IYF7rEYb4oZ7A1Zv8Y0IVRqcJw= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p1.samsung.com (KnoxPortal) with ESMTP id 20200601122118epcas1p1312c035b95997411345eaee29996d610~UauACbal72984029840epcas1p1X; Mon, 1 Jun 2020 12:21:18 +0000 (GMT) Received: from epsmges1p2.samsung.com (unknown [182.195.40.160]) by epsnrtp1.localdomain (Postfix) with ESMTP id 49bDmY4YgmzMqYlp; Mon, 1 Jun 2020 12:21:17 +0000 (GMT) Received: from epcas1p3.samsung.com ( [182.195.41.47]) by epsmges1p2.samsung.com (Symantec Messaging Gateway) with SMTP id F7.24.19033.DB2F4DE5; Mon, 1 Jun 2020 21:21:17 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p4.samsung.com (KnoxPortal) with ESMTPA id 20200601122117epcas1p46da0a6d26a916248d900b32f5a8d81c5~Uat_cUVJP0208002080epcas1p4X; Mon, 1 Jun 2020 12:21:17 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200601122116epsmtrp1b66076f047bf5cb9ed58cae420b956c8~Uat_bvIcp1229312293epsmtrp1B; Mon, 1 Jun 2020 12:21:16 +0000 (GMT) X-AuditID: b6c32a36-159ff70000004a59-00-5ed4f2bdf975 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 29.73.08303.CB2F4DE5; Mon, 1 Jun 2020 21:21:16 +0900 (KST) Received: from W10PB11329 (unknown [10.253.152.129]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200601122116epsmtip265605eeb427b92056df51552e2a076dc~Uat_QSYYe0351103511epsmtip2Z; Mon, 1 Jun 2020 12:21:16 +0000 (GMT) From: "Sungjong Seo" To: "'Tetsuhiro Kohada'" Cc: , , , "'Namjae Jeon'" , , In-Reply-To: <20200531093017.12318-1-kohada.t2@gmail.com> Subject: RE: [PATCH 3/4 v4] exfat: add boot region verification Date: Mon, 1 Jun 2020 21:21:16 +0900 Message-ID: <200001d6380f$260adf80$72209e80$@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 15.0 Thread-Index: AQJWqZqndQR6yzMz7HjQ16/s2RR9CAIQqkuNp7JFjkA= Content-Language: ko X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprLJsWRmVeSWpSXmKPExsWy7bCmvu7eT1fiDFbtU7b4Mfc2i8Wbk1NZ LPbsPclicXnXHDaLy/8/sVgs+zKZxeLH9HoHdo8vc46ze7RN/sfu0XxsJZvHzll32T36tqxi 9Pi8SS6ALSrHJiM1MSW1SCE1Lzk/JTMv3VbJOzjeOd7UzMBQ19DSwlxJIS8xN9VWycUnQNct MwfoFCWFssScUqBQQGJxsZK+nU1RfmlJqkJGfnGJrVJqQUpOgaFBgV5xYm5xaV66XnJ+rpWh gYGRKVBlQk7G0VP/WAoeK1bM27qEuYFxt1QXIyeHhICJxNYXn9i6GLk4hAR2MErsmvaCCcL5 xCjxYsc0dgjnM6PE5nMP2GBapjW/Y4VI7GKUOLf+DVTLS0aJIye2M4FUsQnoSjy58ZMZxBYR 0JM4efI6WDezQCOTxImX2SA2p4ClxOw3z4EmcXAIC9hLLOirBQmzCKhI/Du+kBHE5gUq6bz/ mQ3CFpQ4OfMJC8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0dHFKHH/0VEWkCpOAUuJ2W+es4JMFRawl1jQVwsSZhFQkfh3fCEj iM0LVNJ5/zMbhC0ocXLmExaQcmagBW0bwUqYBeQltr+dwwxxv4LE7k9HWSFusJJYv/gVVI2I xOzONuYJjMKzkEyahTBpFpJJs5B0LGBkWcUomVpQnJueW2xYYJSXWq5XnJhbXJqXrpecn7uJ ERxRWlo7GPes+qB3iJGJg/EQowQHs5II72T1S3FCvCmJlVWpRfnxRaU5qcWHGKU5WJTEeb/O WhgnJJCeWJKanZpakFoEk2Xi4JRqYFrf/fi82bng+KhDItqPyzMO84dzP53SPGupQIbd5Vk9 yvtF2b8crl08Ic7rpMOObY3Ga+pex05rtl5Y9Tzz3x7RFyaP59rv5F11M5J7u02S98c5KnF7 2dOaJ7dkTZQqL/RxUpnafe7JFTcFJsuLWTcf3nFSSX0794Z4W03eT+NFtUEyrzZt3Dojmy/w +42HKoXxjQfTe64efrJuX/uxY0LVd1dcva2xfsvOuH2HprC0Br++Y9P0rH6laKXuLZEQAfdH OhasvPue/JUw8jmwQTLHoVF6fdbOWYt/fmPsjr9t1pkl+9VoTZ/fusXLeT5dWLr47J85k1dc ivV8yfK+LqWikjuUyVJFpmd194b9q2uVWIozEg21mIuKEwGzH0+KFwMAAA== X-CMS-MailID: 20200601122117epcas1p46da0a6d26a916248d900b32f5a8d81c5 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20200531093027epcas1p114ae71536b54ddf42882831cceb007c9 References: <20200531093017.12318-1-kohada.t2@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > Add Boot-Regions verification specified in exFAT specification. > Note that the checksum type is strongly related to the raw structure, so > the'u32 'type is used to clarify the number of bits. > > Signed-off-by: Tetsuhiro Kohada Reviewed-by: Sungjong Seo > --- > Changes in v2: > - rebase with patch 'optimize dir-cache' applied > - just print a warning when invalid exboot-signature detected > - print additional information when invalid boot-checksum detected > Changes in v3: > - based on '[PATCH 2/4 v3] exfat: separate the boot sector analysis' > Changes in v4: > - fix type of p_sig/p_chksum to __le32 > > fs/exfat/exfat_fs.h | 1 + > fs/exfat/misc.c | 14 +++++++++++++ > fs/exfat/super.c | 50 +++++++++++++++++++++++++++++++++++++++++++++ > 3 files changed, 65 insertions(+) > > diff --git a/fs/exfat/exfat_fs.h b/fs/exfat/exfat_fs.h index > 9673e2d31045..eebbe5a84b2b 100644 > --- a/fs/exfat/exfat_fs.h > +++ b/fs/exfat/exfat_fs.h > @@ -514,6 +514,7 @@ void exfat_set_entry_time(struct exfat_sb_info *sbi, > struct timespec64 *ts, > u8 *tz, __le16 *time, __le16 *date, u8 *time_cs); unsigned > short exfat_calc_chksum_2byte(void *data, int len, > unsigned short chksum, int type); > +u32 exfat_calc_chksum32(void *data, int len, u32 chksum, int type); > void exfat_update_bh(struct super_block *sb, struct buffer_head *bh, int > sync); void exfat_chain_set(struct exfat_chain *ec, unsigned int dir, > unsigned int size, unsigned char flags); diff --git > a/fs/exfat/misc.c b/fs/exfat/misc.c index ab7f88b1f6d3..b82d2dd5bd7c > 100644 > --- a/fs/exfat/misc.c > +++ b/fs/exfat/misc.c > @@ -151,6 +151,20 @@ unsigned short exfat_calc_chksum_2byte(void *data, > int len, > return chksum; > } > > +u32 exfat_calc_chksum32(void *data, int len, u32 chksum, int type) { > + int i; > + u8 *c = (u8 *)data; > + > + for (i = 0; i < len; i++, c++) { > + if (unlikely(type == CS_BOOT_SECTOR && > + (i == 106 || i == 107 || i == 112))) > + continue; > + chksum = ((chksum << 31) | (chksum >> 1)) + *c; > + } > + return chksum; > +} > + > void exfat_update_bh(struct super_block *sb, struct buffer_head *bh, int > sync) { > set_bit(EXFAT_SB_DIRTY, &EXFAT_SB(sb)->s_state); diff --git > a/fs/exfat/super.c b/fs/exfat/super.c index 6a1330be5a9a..405717e4e3ea > 100644 > --- a/fs/exfat/super.c > +++ b/fs/exfat/super.c > @@ -491,6 +491,50 @@ static int exfat_read_boot_sector(struct super_block > *sb) > return 0; > } > > +static int exfat_verify_boot_region(struct super_block *sb) { > + struct buffer_head *bh = NULL; > + u32 chksum = 0; > + __le32 *p_sig, *p_chksum; > + int sn, i; > + > + /* read boot sector sub-regions */ > + for (sn = 0; sn < 11; sn++) { > + bh = sb_bread(sb, sn); > + if (!bh) > + return -EIO; > + > + if (sn != 0 && sn <= 8) { > + /* extended boot sector sub-regions */ > + p_sig = (__le32 *)&bh->b_data[sb->s_blocksize - 4]; > + if (le32_to_cpu(*p_sig) != EXBOOT_SIGNATURE) > + exfat_warn(sb, "Invalid exboot-signature(sector > = %d): 0x%08x", > + sn, le32_to_cpu(*p_sig)); > + } > + > + chksum = exfat_calc_chksum32(bh->b_data, sb->s_blocksize, > + chksum, sn ? CS_DEFAULT : CS_BOOT_SECTOR); > + brelse(bh); > + } > + > + /* boot checksum sub-regions */ > + bh = sb_bread(sb, sn); > + if (!bh) > + return -EIO; > + > + for (i = 0; i < sb->s_blocksize; i += sizeof(u32)) { > + p_chksum = (__le32 *)&bh->b_data[i]; > + if (le32_to_cpu(*p_chksum) != chksum) { > + exfat_err(sb, "Invalid boot checksum (boot checksum : > 0x%08x, checksum : 0x%08x)", > + le32_to_cpu(*p_chksum), chksum); > + brelse(bh); > + return -EINVAL; > + } > + } > + brelse(bh); > + return 0; > +} > + > /* mount the file system volume */ > static int __exfat_fill_super(struct super_block *sb) { @@ -503,6 > +547,12 @@ static int __exfat_fill_super(struct super_block *sb) > goto free_bh; > } > > + ret = exfat_verify_boot_region(sb); > + if (ret) { > + exfat_err(sb, "invalid boot region"); > + goto free_bh; > + } > + > ret = exfat_create_upcase_table(sb); > if (ret) { > exfat_err(sb, "failed to load upcase table"); > -- > 2.25.1