From patchwork Mon Jan 29 08:07:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 193315 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp421868dyb; Mon, 29 Jan 2024 00:07:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IG6I/QD1EnsKAQvd3+DuwxJz6ZDgcggoz8vN0qtuy5m/59UkurWbQSI9dXkGL/TOdWcn8Gc X-Received: by 2002:a0d:d2c2:0:b0:5fb:5250:a781 with SMTP id u185-20020a0dd2c2000000b005fb5250a781mr3853260ywd.31.1706515672720; Mon, 29 Jan 2024 00:07:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706515672; cv=pass; d=google.com; s=arc-20160816; b=j+2aNOsYbOVmAYFesPsUgqcjcqj2mK0IzQy6Zk1E1LrovDJEzNJ40s2uSSbXtoGj4K h4/oIyo7dZs1BSRznz+Rxg2BT0yY1MrNe5Z7nbAemDglk4DN2XvIFBi3gpgLxbBrIWLv +niZ2H7hnsOvmOV2/uNcmNnuMoQgGvyfl7hAjcYaxkM9ksKXj5a2Vj4hhUbKPBUExXrb SNn8rYz1Kn2LECJmuLon/qT8tQ7SkhqwzhBN8mmZ4qq+8VRoCHB85orkggiG/iPNG4wH IC4+Y27wVFyhSRMsnI+iVGqrFzhhY7SvfmsSq3eSiuMMDq06m3FoyOmyjyuFxEbGIJOo VJGA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:references:cc:to:from :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature :dkim-signature; bh=SelnU1PmjcEBam/XFIeYfnjb/zVT85VEHjJYVt2fRhM=; fh=P7I85FIabZcM8ojWdeG8ABpTZepe/Xtte9jKWDfUHBM=; b=TZUH46Vy5m/vxzbWBKu7NZ75202YwzJFG7VldvbARLJ0NSxjn8gdX8YN34Fzvgzm0f w7aXX4fMI+vTYM6DMgjRClYQ95V3MVDwhmifsSvp+NcELSGnbz630OMgyLHRbkXw95Ya IFWeWDQE3Mg5IHqLPsQSwIMJjHgRjVtAuWtepRNdAR1fGnwfKkBb2VWhn537CyiTi885 ZirgcoxlWfjySrrKOElBOPO4tza8G080X3OmL8P5cktcx0ZxrsfjhbrxGgvbPGR4+8cf TJxm4hZ6k+xbVbCuNpCSKTvwukOeCPRM2KsrUzCcrtgjFRcnVswp3jm3yAiV/vc27QwS YnLQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=u6Vv7kMM; dkim=pass header.i=@paragon-software.com header.s=mail header.b=Wtto7Qtd; arc=pass (i=1 spf=pass spfdomain=paragon-software.com dkim=pass dkdomain=paragon-software.com dkim=pass dkdomain=paragon-software.com dmarc=pass fromdomain=paragon-software.com); spf=pass (google.com: domain of linux-kernel+bounces-42326-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42326-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p26-20020a05620a22fa00b00783f53a5507si3345727qki.741.2024.01.29.00.07.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 00:07:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42326-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=u6Vv7kMM; dkim=pass header.i=@paragon-software.com header.s=mail header.b=Wtto7Qtd; arc=pass (i=1 spf=pass spfdomain=paragon-software.com dkim=pass dkdomain=paragon-software.com dkim=pass dkdomain=paragon-software.com dmarc=pass fromdomain=paragon-software.com); spf=pass (google.com: domain of linux-kernel+bounces-42326-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42326-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 80F961C22E3A for ; Mon, 29 Jan 2024 08:07:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F291C53E0A; Mon, 29 Jan 2024 08:07:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="u6Vv7kMM"; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b="Wtto7Qtd" Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CC22C537E4; Mon, 29 Jan 2024 08:07:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=35.157.23.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706515654; cv=none; b=Yy5ADQkFG8/J4WvD9QxVJd+bVQt7b85Yi+P9m7kp7c5PSd3zBa9q7GG5YIo+97q7mvf7Dg0s3glQzQ7GJHIQPDY2K/GIYO8Lw60ntxzQ4b7Iarx/I6+nCjtZS8tRJczUrESEXc1IDteDObGNCAOu6589LnUSsbz8IslN4do2Yvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706515654; c=relaxed/simple; bh=ebmE+3+S0pyuODXXnBFsAaOW8KZdxmR2O/v1cJbjSO4=; h=Message-ID:Date:MIME-Version:Subject:From:To:CC:References: In-Reply-To:Content-Type; b=FWxT1FbR2DkjL75FmaP6cR/1kVVcJrTqCjP8+7N1A+pRvoHlMHsOHEJxTj7NCYA23n6tZeGcbeb3f4XU5PyCliTzO+J5F1GoV7reDCv6SgXegfVnTpjyHrZoqYZ+naW8BkprqphZWgRSyNN0EtiHMzgjjWp1VZuUjRavnWTy2ZM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com; spf=pass smtp.mailfrom=paragon-software.com; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=u6Vv7kMM; dkim=pass (1024-bit key) header.d=paragon-software.com header.i=@paragon-software.com header.b=Wtto7Qtd; arc=none smtp.client-ip=35.157.23.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=paragon-software.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=paragon-software.com Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 7FDD4211A; Mon, 29 Jan 2024 08:00:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1706515239; bh=SelnU1PmjcEBam/XFIeYfnjb/zVT85VEHjJYVt2fRhM=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=u6Vv7kMMhVrF1vzHeBcbgCVN50yqGtaSjYEW8ON03Jpi9XNbYJTXzaxT3SL7XzqkR 6cVEFcLHJqpCZPwiKlGjpz4nt/DQ35sChxYkSuds3Mglu5URBYpWvpL+eCJTyNUdyU PwK2jkF7UHG1AxfabfmC4+8rZX4YlrHvxS8NDj4A= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id CD4702135; Mon, 29 Jan 2024 08:07:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1706515649; bh=SelnU1PmjcEBam/XFIeYfnjb/zVT85VEHjJYVt2fRhM=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=Wtto7QtdPRPmS/B/yMBSisnCRJ6+b1ajjrp4oEe6VyxUX0X4ZSj8qrypAZAtWHZj9 lYzyzKoRORuHV0Debb33xTzi+KuDmwW4b2O3si54WDc+C+3enMK+RyZdkLoaGZNKuK ZTtdTn5ydRwrRNARy+ocBiKd+dGUC7ujq+i7Y2SQ= Received: from [192.168.211.199] (192.168.211.199) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Mon, 29 Jan 2024 11:07:29 +0300 Message-ID: <7d42dc06-2f7f-40b4-8d9f-89eebd0a8f06@paragon-software.com> Date: Mon, 29 Jan 2024 11:07:29 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 1/5] fs/ntfs3: Prevent generic message "attempt to access beyond end of device" Content-Language: en-US From: Konstantin Komarov To: CC: , References: In-Reply-To: X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789411378131784965 X-GMAIL-MSGID: 1789411378131784965 It used in test environment. Signed-off-by: Konstantin Komarov ---  fs/ntfs3/fsntfs.c  | 24 ++++++++++++++++++++++++  fs/ntfs3/ntfs_fs.h | 14 +-------------  2 files changed, 25 insertions(+), 13 deletions(-)                 bool simple); @@ -1032,19 +1033,6 @@ static inline u64 bytes_to_block(const struct super_block *sb, u64 size)      return (size + sb->s_blocksize - 1) >> sb->s_blocksize_bits;  } -static inline struct buffer_head *ntfs_bread(struct super_block *sb, -                         sector_t block) -{ -    struct buffer_head *bh = sb_bread_unmovable(sb, block); - -    if (bh) -        return bh; - -    ntfs_err(sb, "failed to read volume at offset 0x%llx", -         (u64)block << sb->s_blocksize_bits); -    return NULL; -} -  static inline struct ntfs_inode *ntfs_i(struct inode *inode)  {      return container_of(inode, struct ntfs_inode, vfs_inode); diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index 321978019407..ae2ef5c11868 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -1007,6 +1007,30 @@ static inline __le32 security_hash(const void *sd, size_t bytes)      return cpu_to_le32(hash);  } +/* + * simple wrapper for sb_bread_unmovable. + */ +struct buffer_head *ntfs_bread(struct super_block *sb, sector_t block) +{ +    struct ntfs_sb_info *sbi = sb->s_fs_info; +    struct buffer_head *bh; + +    if (unlikely(block >= sbi->volume.blocks)) { +        /* prevent generic message "attempt to access beyond end of device" */ +        ntfs_err(sb, "try to read out of volume at offset 0x%llx", +             (u64)block << sb->s_blocksize_bits); +        return NULL; +    } + +    bh = sb_bread_unmovable(sb, block); +    if (bh) +        return bh; + +    ntfs_err(sb, "failed to read volume at offset 0x%llx", +         (u64)block << sb->s_blocksize_bits); +    return NULL; +} +  int ntfs_sb_read(struct super_block *sb, u64 lbo, size_t bytes, void *buffer)  {      struct block_device *bdev = sb->s_bdev; diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 2b54ae94440f..81f7563428ee 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -586,6 +586,7 @@ bool check_index_header(const struct INDEX_HDR *hdr, size_t bytes);  int log_replay(struct ntfs_inode *ni, bool *initialized);  /* Globals from fsntfs.c */ +struct buffer_head *ntfs_bread(struct super_block *sb, sector_t block);  bool ntfs_fix_pre_write(struct NTFS_RECORD_HEADER *rhdr, size_t bytes);  int ntfs_fix_post_read(struct NTFS_RECORD_HEADER *rhdr, size_t bytes,