Received: by 2002:ab2:7903:0:b0:1fb:b500:807b with SMTP id a3csp685227lqj; Sun, 2 Jun 2024 18:07:59 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVbwH6eiGUHOUOrx3XdK38SUorl6qbGzTeguYZU+/O4T+CC840RUd2HoB4h/JHUUPil8Kkuw1J2I8Ahs0+lA4FX1oDi2KaKEg/ne/9OKg== X-Google-Smtp-Source: AGHT+IGSsM3M9Ng8/tn+ZO/NkGlfbHRdiygqnav0CFlmIcstjiqx7natdeoBPN+lgytNtRqIfVoW X-Received: by 2002:a50:9f65:0:b0:579:e690:8349 with SMTP id 4fb4d7f45d1cf-57a5b7ac415mr2235517a12.15.1717376879579; Sun, 02 Jun 2024 18:07:59 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717376879; cv=pass; d=google.com; s=arc-20160816; b=jkjeS1MM/Bg4vK9x/9PplV7mpJuJGMAN2Xj0SoYiazy7jm0R5tKhJYd2VNZ7J9RRUl vE4ii8+qC62QdNgAwB4HmanZARcDQKnMSHwoOUWMIQskN5p00Cl+LTA8ry9tJ9abXFVK uPW/DHGeg3Zh08Ay4eUiSquDnDuo3LW7HxcVAEMjnxDkJO5T4Kk006wBtlMrWDHaHWLf AqYkH2VkKm/kys59cCP88PB4bsmfNu2Jtdev27wS5In+/YEQbqaqbrlV/rxwgo6UkwlV hYMaEVL8o0rqKphc4kjtfygevejwRBCWxWjS6tJQnYQfPAkwyUkTyTYm3QxeNz4JNKd4 8evA== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=TG0W7PxAtanmcoxyAxGMshJFPoOMPjFrebDI8mi6bKk=; fh=pH4sHm5vfKfB3xcEBv4X+m87lrqx8rXkts85sOXy09k=; b=hlgsO2M6xRIH0sCPGEVp95Pc1HZhgXAq26+MqgDI3dk/xsFXOCkYWqOsbXYL5LkbG1 ym0mTNzydSfhWJ5MuxucvpWGX3mZixyZ9X/oPNUMsxzxbxyx9Rb5NQBNXfviQw9O8CB+ e9ICJgYLnXjbhYOlyLLzhCApAVJbqVSkWHMWJ2B2/sv3Fu46QHc/tdcx1F+722fBM9Bi 9Rsz4viDkEPqJnNcGSEtX4IHiHDSUvtVRjZs9aiWkXK7PBkgOUzOb7dZfFK1hkUpme7n qbfsXkvVVhuEYs7HJ6BG3qRl5Ao4pwlebEG4fMOd0sfgzF6YEeIx4e3EubJoDzAauPrl 4HYQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=D8I6psrO; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-198513-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198513-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57a31b80da1si3654198a12.70.2024.06.02.18.07.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jun 2024 18:07:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-198513-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=D8I6psrO; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-198513-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-198513-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 am.mirrors.kernel.org (Postfix) with ESMTPS id 4CE1A1F216BD for ; Mon, 3 Jun 2024 01:07:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E958C15C9; Mon, 3 Jun 2024 01:07:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="D8I6psrO" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0F0C715C3; Mon, 3 Jun 2024 01:07:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717376872; cv=none; b=IGedzKrTmRYIvd7m4XxPWKlOdmmqbMytkLKp2yd6K/e1W25nYKZbZ5mKI1sBMKKZ4F3crWLcnNaOIrzVB8FSn1g3bbsYewaMYLYzDLOc4j3rzBb2E5/P32PASbb2/dcwhP9tC2SqTyK64uA7DJOqPlKzbbMndTXpC77z584r4Dc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717376872; c=relaxed/simple; bh=GyS3Y18rQu9OR8fVI2mcAQN7lotZDqwO7TwKorRv4EU=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=pbbksNBeSvjra6wOIU2xygXGpYeQIvZQeITSDHzgLFX5F1YBbcXPpwo3M65f98i+x18cT/6nAMDkVVlh9qvMwEE23v82ecTtxmkglftwsupdG+PAVs6f951A/+eCBDknC+5H6s0G64fygvIVQYMjUkmrXYYDiJNYUPLiaJswinI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D8I6psrO; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id EA742C2BBFC; Mon, 3 Jun 2024 01:07:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717376871; bh=GyS3Y18rQu9OR8fVI2mcAQN7lotZDqwO7TwKorRv4EU=; h=From:To:Cc:Subject:Date:From; b=D8I6psrOyyBzeNkPVfedoZlzta/z5THqXNORMTgZ5A0RQI/v+TJOqRqmH4D7+/PUj gHTflezQyoMqWeED145AQQ3KUlN3HipnoZnclRTN8m2aodbbtowkSf7PoWHuoUy7UO L1lLnFlyxMedO0CZhiH6sqPRMouCrLxpJ5tnpgeYtp8pelFoNC9jCCtMgllMvemqPI FWIMtR4GWWlz8i1M2OQ/GbhOkyb9xO3xpG3qowJE88M+jv/CiAasmw1xSH6ueqTuTz gRHkq4SxsKSKuvle9yl8+4TCYQpgBYI3vQ+QYC8lHDhp+CtM/ToFNNxniYIx06zlLV avCdw2mc20OHA== From: Chao Yu To: jaegeuk@kernel.org Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , stable@vger.kernel.org, syzbot+848062ba19c8782ca5c8@syzkaller.appspotmail.com Subject: [PATCH] f2fs: fix return value of f2fs_convert_inline_inode() Date: Mon, 3 Jun 2024 09:07:45 +0800 Message-Id: <20240603010745.2246488-1-chao@kernel.org> X-Mailer: git-send-email 2.40.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit If device is readonly, make f2fs_convert_inline_inode() return EROFS instead of zero, otherwise it may trigger panic during writeback of inline inode's dirty page as below: f2fs_write_single_data_page+0xbb6/0x1e90 fs/f2fs/data.c:2888 f2fs_write_cache_pages fs/f2fs/data.c:3187 [inline] __f2fs_write_data_pages fs/f2fs/data.c:3342 [inline] f2fs_write_data_pages+0x1efe/0x3a90 fs/f2fs/data.c:3369 do_writepages+0x359/0x870 mm/page-writeback.c:2634 filemap_fdatawrite_wbc+0x125/0x180 mm/filemap.c:397 __filemap_fdatawrite_range mm/filemap.c:430 [inline] file_write_and_wait_range+0x1aa/0x290 mm/filemap.c:788 f2fs_do_sync_file+0x68a/0x1ae0 fs/f2fs/file.c:276 generic_write_sync include/linux/fs.h:2806 [inline] f2fs_file_write_iter+0x7bd/0x24e0 fs/f2fs/file.c:4977 call_write_iter include/linux/fs.h:2114 [inline] new_sync_write fs/read_write.c:497 [inline] vfs_write+0xa72/0xc90 fs/read_write.c:590 ksys_write+0x1a0/0x2c0 fs/read_write.c:643 do_syscall_x64 arch/x86/entry/common.c:52 [inline] do_syscall_64+0xf5/0x240 arch/x86/entry/common.c:83 entry_SYSCALL_64_after_hwframe+0x77/0x7f Cc: stable@vger.kernel.org Reported-by: syzbot+848062ba19c8782ca5c8@syzkaller.appspotmail.com Closes: https://lore.kernel.org/linux-f2fs-devel/000000000000d103ce06174d7ec3@google.com Signed-off-by: Chao Yu --- fs/f2fs/inline.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/inline.c b/fs/f2fs/inline.c index 0203c3baabb6..1fba5728be70 100644 --- a/fs/f2fs/inline.c +++ b/fs/f2fs/inline.c @@ -221,8 +221,10 @@ int f2fs_convert_inline_inode(struct inode *inode) struct page *ipage, *page; int err = 0; - if (!f2fs_has_inline_data(inode) || - f2fs_hw_is_readonly(sbi) || f2fs_readonly(sbi->sb)) + if (f2fs_hw_is_readonly(sbi) || f2fs_readonly(sbi->sb)) + return -EROFS; + + if (!f2fs_has_inline_data(inode)) return 0; err = f2fs_dquot_initialize(inode); -- 2.40.1