Received: by 2002:a05:7412:1e0b:b0:fc:a2b0:25d7 with SMTP id kr11csp351037rdb; Thu, 15 Feb 2024 02:00:14 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWcZNhdg5uHwFMAISjD0KSvbvNaV6Lur3i1e4jnIqfRfwridDI4MfJcI2oWAV/oCqtGquNJNfQEG42gpuR467MJu87qBNTILL3aNAj9+w== X-Google-Smtp-Source: AGHT+IEwAmQ4RarzrFbpVK8Jmz6rgk2VukBO98PkNIYY6TRG1Pmfcn7rRbK836u4jGCK8FyS6GbB X-Received: by 2002:a05:6a20:9f05:b0:19c:9f1b:1d8d with SMTP id mk5-20020a056a209f0500b0019c9f1b1d8dmr1631273pzb.12.1707991214546; Thu, 15 Feb 2024 02:00:14 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707991214; cv=pass; d=google.com; s=arc-20160816; b=PmYswq60IEimI5grr4aRbg85iPVO4rI06KwIrWoiit5VWA1nXs3a5e+4tw7yVW+w4I V/EApupKGVAcmQ73dqlJDQKndr70WLXgy3r0ou5IUH1y6QhKX2Ptk7pgk3TGTy2MIlH0 O98lagFH350s8m8VITryJFNC/X4Cr4u62+bKtOhI1tdf6HLvaejAuL49XXjFqX4w1oeH 1WoQWZTvBgpPOmCH+xcqcVo0IsR9/YZ6zE+i580Q6oPrWWmVZEE/vKLegvkuVWpZMOxq caVrdIoYg8fn+GO2tzvTi9nfDLvPWtEMH82CbcOTMWtoRzAr3qEBZy1UL5ekR0iHnb46 Uq8Q== 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=TZW5dJ0nv7fo+LI90ijtR+d2/ZkIfNS9bRkcnAAFJTI=; fh=gTmZnfBiRyflkvAgAsZJD2Tb4iTcgMJStenyctPm02w=; b=OEAJcIJLWz0afFOGHcdWbAum0h0iFx3lEBWkQwcA5EIkGM0GPjs/rKlB8i/Cs4/2fA NX0jtCK9dL70Cj9zdof5LWJCMKZRvkR6G8SZQAz/7qricEA+1tE9qsXq6pw7cKJuGaec hWGs6QolsSYtNBaVPqIJytsn0zpbnh60HzIKfdgwcjna6bDi6wERQsVK826NnbNij1bl BF0Q+KKmjqwmHmmbU4ye6f7nd1+hjpV4RMTgoLUdGZQ1qODt8Bliu/Awx2iQ3Vr+jS0V bHFVxhUxkc07D2mCFpYOhs/BkzEWiNRg5orNU024eXwmQfj6VwECOyamE0vik7QC/3zI shyg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=BmByWoGm; arc=pass (i=1 spf=pass spfdomain=pankajraghav.com dkim=pass dkdomain=pankajraghav.com); spf=pass (google.com: domain of linux-kernel+bounces-63232-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63232-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id md23-20020a17090b23d700b00298beb88a88si2784331pjb.117.2024.02.15.02.00.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 02:00:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63232-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@pankajraghav.com header.s=MBO0001 header.b=BmByWoGm; arc=pass (i=1 spf=pass spfdomain=pankajraghav.com dkim=pass dkdomain=pankajraghav.com); spf=pass (google.com: domain of linux-kernel+bounces-63232-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63232-linux.lists.archive=gmail.com@vger.kernel.org" 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B28E4289417 for ; Tue, 13 Feb 2024 09:42:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B1B7E51000; Tue, 13 Feb 2024 09:38:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pankajraghav.com header.i=@pankajraghav.com header.b="BmByWoGm" Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) (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 6109F225A9; Tue, 13 Feb 2024 09:37:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707817080; cv=none; b=rP3Krp1aBNVuQD1YF7S7F/w2w5C0KxV3xQAfzyxww08979PudwBY4fZ1g1Yt6VPR9AA+jgH4w8v1OJILzGxR6wOLGjvJCxosziFvWAAAd6bzWzUZY4DuBqk0GKr0Hz5hYbQW5ikRsNQTgvzoAKVQGZvyKU+ItSzyIXf5k02FplE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707817080; c=relaxed/simple; bh=RoUxwy82xaGykdNbB9bQNH3nvpBbWo6kSTGPBWPwdjE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BvEQq+7EKs6K9WcR6y5RYJ/DxCXVi0drGGE66hP+Au0wRSZbe6Xf3hOSHMqthzp+2vXm2bprwUC5nnf4yFvRhrQTrZrVpDfP9ZWsOiQsggZal7e2nDCV58zfg8AovZ3p0p47Mspff7y/7rHiiKEZLCwvwr0liAxvqKikLMxDUjY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none 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=BmByWoGm; arc=none smtp.client-ip=80.241.56.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none 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-201.mailbox.org (Postfix) with ESMTPS id 4TYx8347SMz9stR; Tue, 13 Feb 2024 10:37:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pankajraghav.com; s=MBO0001; t=1707817075; 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=TZW5dJ0nv7fo+LI90ijtR+d2/ZkIfNS9bRkcnAAFJTI=; b=BmByWoGmvp+kEWIRd+4bCnx1c2aolG8l1MFYl3diqfPl1tqcl9YnuViapkcDsVIqIxJBzY QXT/YcPpK9B3nuaFEVuFdW5R6AlwojOALukyjqK/Yy3Te36bjXCR40bUAM+uoMezT5lgKn NC+RH4zuH3m2XBI4ZPaWaxWn/2hQpPmmrP0HjKHmzPORWmz+z4fAA3h98UmbZDvBT2S2Vk isdlWNDiTRE+qpjyeeVHFzn5lQttGKmWNJ2UkMcSSryAvZdDhvlh337EwDRWCUh4cfyLwr x0EH5x4x/v33DNXaAiV4YYn1JWJnST4sjQeqW1JYK0nqjGowTU6abq3eQaKg2g== From: "Pankaj Raghav (Samsung)" To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: mcgrof@kernel.org, gost.dev@samsung.com, akpm@linux-foundation.org, kbusch@kernel.org, djwong@kernel.org, chandan.babu@oracle.com, p.raghav@samsung.com, linux-kernel@vger.kernel.org, hare@suse.de, willy@infradead.org, linux-mm@kvack.org, david@fromorbit.com Subject: [RFC v2 10/14] iomap: fix iomap_dio_zero() for fs bs > system page size Date: Tue, 13 Feb 2024 10:37:09 +0100 Message-ID: <20240213093713.1753368-11-kernel@pankajraghav.com> In-Reply-To: <20240213093713.1753368-1-kernel@pankajraghav.com> References: <20240213093713.1753368-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: 4TYx8347SMz9stR 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 --- 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