Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp93553lqb; Thu, 14 Mar 2024 06:26:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWkmNPyVA+dssJmXRmSmZTcOVq6tIUSvgVtb1TRhr310dmltGd1t4QcZqNFRaUOpQtjttT/27EgaWrl825ZBf8Xss+bJHFWmMiyfZTkTw== X-Google-Smtp-Source: AGHT+IH8gs+CCNVgRO4iWUHNcq0rnpO8fXNNi2Ne8/v+6Z9vqi1Wjriz/k8Z93S0t6Dk+Hdb5Wd4 X-Received: by 2002:a17:902:ec88:b0:1dc:cee2:5ffc with SMTP id x8-20020a170902ec8800b001dccee25ffcmr2100708plg.6.1710422783170; Thu, 14 Mar 2024 06:26:23 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710422783; cv=pass; d=google.com; s=arc-20160816; b=t+mtc/wtPSfC3AEzj32NSlbff0fyJ8of5rOR+YUoVI8v97h/9rLbpS3hHDTmf7in6R L+PGs9CJxqk41Q+oX+QpockNaaPZCudd/c/Wb76kwxUcHaZJJCHEPGEUPzpFNyR9JSwE u0hAZUrbkeuS9jlgIIc2CN1yuz5Lr1Nr2hDU8Y5InWr693GEe+96URSk+9gCIzYRbJgD OMHbbd7f3RLEP1kiZ4i8qSFJBnaTaaDaPnzXbkjfho0VyFgpoOJm1eRblBrBtBgGExkT nAACUsExFbOWsFj8bUnMrQanELQxI0/OXzIEdyQGseIGagsLBzS9L9Hip+wvRXHE5ZX3 Sx1g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=CoSlfuEyGkiaGErrLwm5tBbxdIgWjqVT8F2G+alxKAU=; fh=j3uz2NgZFfq57/Snoylk35aIHaL6SCDmmQDWQGY3sTA=; b=q3GAplQkCpfrkWuCo+CiO8GLy9PxU0gCU15ci8xG9/wqdGNyn4JVQchbazUrarruqD 0CQaUJBpq9ul7w0Dnhzvhuy9jC4WI7JWmGjabbdevXrdY9ya4RUwpgyAyFpIwr+Ha88S dSCNXbfI+ZEYy7C7EfWB/ykPw5tBXApXSSwk38H+5ps5G7XMovsJXv4mk5vrXXP8QoEi 5cVfbBXosiroJOx6CGIsdcafREhMdMUTfjGMYsHoBvnInuh/miaIZhOcEUi681wH/K9W Ov1oR8sltL1yaO8k97ZRBnUzM+M5PBb+Eaxh3SrLs1+7PHhkGwlUBBgPEkvCwc60lXAL GWKQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=mvvw8Uxd; arc=pass (i=1 spf=pass spfdomain=pankajraghav.com dkim=pass dkdomain=pankajraghav.com dmarc=pass fromdomain=pankajraghav.com); spf=pass (google.com: domain of linux-kernel+bounces-102179-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102179-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pankajraghav.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id u18-20020a170902e21200b001dcfc0b6a42si1426154plb.180.2024.03.14.06.26.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 Mar 2024 06:26:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-102179-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=mvvw8Uxd; arc=pass (i=1 spf=pass spfdomain=pankajraghav.com dkim=pass dkdomain=pankajraghav.com dmarc=pass fromdomain=pankajraghav.com); spf=pass (google.com: domain of linux-kernel+bounces-102179-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-102179-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pankajraghav.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id B24F8B2790F for ; Wed, 13 Mar 2024 18:18:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1C901998BF; Wed, 13 Mar 2024 17:03:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b="mvvw8Uxd" Received: from mout-p-103.mailbox.org (mout-p-103.mailbox.org [80.241.56.161]) (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 8BE6B199896; Wed, 13 Mar 2024 17:03:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.161 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710349415; cv=none; b=mJgbBAtf/e33SBzU6Fjr9WdRgMFj7JI8hiGOuOJHMrpor/DIwK1i5cNLKbw/uZA3Lo42dNORH05q0DeMUkWvK6SuqJiMbWGWAjIx4H3oFpXPsbmCGW6xKSVaRnEy/s4qEQvaiftuGD/Ijt2qt0b/FC6W5qSuuC6/IPVdxz2OI6E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710349415; c=relaxed/simple; bh=OPjPelr7jC5j/AA2ZEydqVDJmFXOxA3MXRxWvzjeqDU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=G1efBD2hwGcC7x4yH4uum4uxdvFpyA5GH2SwTI7LCy4r3O8PU14HG5loau9w3oT5Y+/kPYGcG2SlEQTytwE3IAhAGkRBxyqXrV7cIaVUBRb64Ydd1HztIz7ik2iAdjLRHH/1n+6tPcI+KsvS3KhnR6UCvaFSc3BGfQ0UEP++x4A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pankajraghav.com; spf=pass smtp.mailfrom=pankajraghav.com; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b=mvvw8Uxd; arc=none smtp.client-ip=80.241.56.161 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pankajraghav.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pankajraghav.com Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-103.mailbox.org (Postfix) with ESMTPS id 4Tvxfp0XHQz9sjG; Wed, 13 Mar 2024 18:03:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1710349410; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CoSlfuEyGkiaGErrLwm5tBbxdIgWjqVT8F2G+alxKAU=; b=mvvw8Uxd8FI+cZwtRvS7Jb6PzVhcuKI2aUQbkfgZAXBDtjhGQc6l/aHdA/AuoMYeLf+Pha JCQRnn+aIlO10MBf3ldx/ILo5zGxFbvlXtliBuGk8I6tmj9crdNElXPe7JhhVnVL0YLvPx LcYQMAhx+gx+SIMNo/J1uYdpG21GWg6Pb7M8jLF7uAaV+FC9tnL6YC2H9w32hGf2WG4AI6 fQ1dBQ7uxhT+3f/VbS3J8HxQWXhZ1lxrpQZeNv4/66sHoQuND7xbilehbB17lzfXSqHkiD OamFwpDDrG1taP1i/YuGszkIkYVB9r3HPNQFh+JapI6Y5/q/DwMfYzwX3Z1bdQ== From: "Pankaj Raghav (Samsung)" To: willy@infradead.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: gost.dev@samsung.com, chandan.babu@oracle.com, hare@suse.de, mcgrof@kernel.org, djwong@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, david@fromorbit.com, akpm@linux-foundation.org, Pankaj Raghav Subject: [PATCH v3 08/11] iomap: fix iomap_dio_zero() for fs bs > system page size Date: Wed, 13 Mar 2024 18:02:50 +0100 Message-ID: <20240313170253.2324812-9-kernel@pankajraghav.com> In-Reply-To: <20240313170253.2324812-1-kernel@pankajraghav.com> References: <20240313170253.2324812-1-kernel@pankajraghav.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4Tvxfp0XHQz9sjG From: Pankaj Raghav iomap_dio_zero() will pad a fs block with zeroes if the direct IO size < fs block size. iomap_dio_zero() has an implicit assumption that fs block size < page_size. This is true for most filesystems at the moment. If the block size > page size, this will send the contents of the page next to zero page(as len > PAGE_SIZE) to the underlying block device, causing FS corruption. iomap is a generic infrastructure and it should not make any assumptions about the fs block size and the page size of the system. Signed-off-by: Pankaj Raghav Reviewed-by: Darrick J. Wong --- fs/iomap/direct-io.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fs/iomap/direct-io.c b/fs/iomap/direct-io.c index bcd3f8cf5ea4..04f6c5548136 100644 --- a/fs/iomap/direct-io.c +++ b/fs/iomap/direct-io.c @@ -239,14 +239,23 @@ static void iomap_dio_zero(const struct iomap_iter *iter, struct iomap_dio *dio, struct page *page = ZERO_PAGE(0); struct bio *bio; - bio = iomap_dio_alloc_bio(iter, dio, 1, REQ_OP_WRITE | REQ_SYNC | REQ_IDLE); + WARN_ON_ONCE(len > (BIO_MAX_VECS * PAGE_SIZE)); + + bio = iomap_dio_alloc_bio(iter, dio, BIO_MAX_VECS, + REQ_OP_WRITE | REQ_SYNC | REQ_IDLE); fscrypt_set_bio_crypt_ctx(bio, inode, pos >> inode->i_blkbits, GFP_KERNEL); + bio->bi_iter.bi_sector = iomap_sector(&iter->iomap, pos); bio->bi_private = dio; bio->bi_end_io = iomap_dio_bio_end_io; - __bio_add_page(bio, page, len, 0); + while (len) { + unsigned int io_len = min_t(unsigned int, len, PAGE_SIZE); + + __bio_add_page(bio, page, io_len, 0); + len -= io_len; + } iomap_dio_submit_bio(iter, dio, bio, pos); } -- 2.43.0