Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3253481rwb; Mon, 15 Aug 2022 22:23:30 -0700 (PDT) X-Google-Smtp-Source: AA6agR7MCaECDfHoXbG76B+cPMa3x8OU99bjYGz5M8FEOiHVYGxbluwgDHIiLeK5jhwBG03AG9IA X-Received: by 2002:a05:6a00:1688:b0:517:cf7b:9293 with SMTP id k8-20020a056a00168800b00517cf7b9293mr19645116pfc.7.1660627409817; Mon, 15 Aug 2022 22:23:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660627409; cv=none; d=google.com; s=arc-20160816; b=g/Z6ABtTwz5IGUF0QBSakdYQLzTkS82kUA2cNR3JiZou+YeDPEKDeaC6UBbCPsadqj rbl2++fvZfn0BaEt2buycARoo4wDPoGWAiz8VpTWDmvv7dKmhYL7u3jVBauNiPxmVboS 2kLcQgGTy/V/ycF9WGBtzljY5DlrkhdBd4wCPhJA6Uidbxw6tILQfh+g/w9mNMs9yjC/ BVHwnHv6QNcykjFUltjeHFgm52275WhSpuMnqd+I3UOU08MrFAXPIYvq1Jeu0TV5R1ad K3p+Ai4xtHym5Tbaqt5PgN07U9biCclTl9gsd6icMPbevruD7DtklhCc2ZuTaNQN+pkP 1VtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0QfQD3qkBxjvvbghLhSfcuxg4ojSOe/v94MFTDPXSrE=; b=zEjzgR3HGRKMfZ2UzsTu1mo9Wt1Pxgclg5dyHUSMWWAomWVKZ7To46UGbjdXHxRljx qbK9jvXO9tZebWutWVEXAs+azV/zonhoRLU4ctrnhp80b+zeGLlIVhGwA4bTKiVbcKW5 PcpNh1WmmyuWBCp/Uf1SwDIXpkIo1OgY53r9UqSeHSvba/vAo8qbS/49h5Xf7Dx315tD scm02A3uCE5KsgtlaJixEp7F2C/0zDiReHBYmWIMkROoVyjfg5mTjZ4DWk9plmgFg+Au 4pyFgvc0e8JCb01PuAWoYTDQntPqDpGM3tLtxBYbonruTBC+qcYZJr8ORA1FpkEjZUrq aV9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ezb8CCN6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s38-20020a056a0017a600b0052b1e2f86ccsi12865072pfg.321.2022.08.15.22.23.16; Mon, 15 Aug 2022 22:23:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Ezb8CCN6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233857AbiHPE6P (ORCPT + 99 others); Tue, 16 Aug 2022 00:58:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233801AbiHPE5A (ORCPT ); Tue, 16 Aug 2022 00:57:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1007BC10A; Mon, 15 Aug 2022 13:51:30 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 588D2B811AB; Mon, 15 Aug 2022 20:51:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE332C433C1; Mon, 15 Aug 2022 20:51:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660596688; bh=KhMDwJOQg4vOSTjVp5iqBX9AP8GhSSqZWa6KYBVpmTA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ezb8CCN6TqlR/00R6TISF4uajzwBK5kzlraEz1KTz2gFFwBPgM1N7XIgh+V/qqLfE AE7UvYMaeLw6cWSqFoDXMfO3AZg/3yN6SAgvy5uRMAczvd4hVTvirVNQY3ioK3IyRP j/dk/2DkqKKzmxSu5wZuNzlvCd2082xvZMvf1rHs= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, stable@kernel.org, Torge Matthies , Zhang Yi , Theodore Tso , Sasha Levin Subject: [PATCH 5.19 1116/1157] ext4: fix reading leftover inlined symlinks Date: Mon, 15 Aug 2022 20:07:52 +0200 Message-Id: <20220815180524.972316753@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhang Yi [ Upstream commit 5a57bca9050d740ca37184302e23d0e7633e3ebc ] Since commit 6493792d3299 ("ext4: convert symlink external data block mapping to bdev"), create new symlink with inline_data is not supported, but it missing to handle the leftover inlined symlinks, which could cause below error message and fail to read symlink. ls: cannot read symbolic link 'foo': Structure needs cleaning EXT4-fs error (device sda): ext4_map_blocks:605: inode #12: block 2021161080: comm ls: lblock 0 mapped to illegal pblock 2021161080 (length 1) Fix this regression by adding ext4_read_inline_link(), which read the inline data directly and convert it through a kmalloced buffer. Fixes: 6493792d3299 ("ext4: convert symlink external data block mapping to bdev") Cc: stable@kernel.org Reported-by: Torge Matthies Signed-off-by: Zhang Yi Tested-by: Torge Matthies Link: https://lore.kernel.org/r/20220630090100.2769490-1-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/ext4.h | 1 + fs/ext4/inline.c | 30 ++++++++++++++++++++++++++++++ fs/ext4/symlink.c | 15 +++++++++++++++ 3 files changed, 46 insertions(+) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index 75b8d81b2469..adfc30ee4b7b 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -3583,6 +3583,7 @@ extern struct buffer_head *ext4_get_first_inline_block(struct inode *inode, extern int ext4_inline_data_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, int *has_inline, __u64 start, __u64 len); +extern void *ext4_read_inline_link(struct inode *inode); struct iomap; extern int ext4_inline_data_iomap(struct inode *inode, struct iomap *iomap); diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index cff52ff6549d..1fa36cbe09ec 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -1588,6 +1589,35 @@ int ext4_read_inline_dir(struct file *file, return ret; } +void *ext4_read_inline_link(struct inode *inode) +{ + struct ext4_iloc iloc; + int ret, inline_size; + void *link; + + ret = ext4_get_inode_loc(inode, &iloc); + if (ret) + return ERR_PTR(ret); + + ret = -ENOMEM; + inline_size = ext4_get_inline_size(inode); + link = kmalloc(inline_size + 1, GFP_NOFS); + if (!link) + goto out; + + ret = ext4_read_inline_data(inode, link, inline_size, &iloc); + if (ret < 0) { + kfree(link); + goto out; + } + nd_terminate_link(link, inode->i_size, ret); +out: + if (ret < 0) + link = ERR_PTR(ret); + brelse(iloc.bh); + return link; +} + struct buffer_head *ext4_get_first_inline_block(struct inode *inode, struct ext4_dir_entry_2 **parent_de, int *retval) diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c index d281f5bcc526..3d3ed3c38f56 100644 --- a/fs/ext4/symlink.c +++ b/fs/ext4/symlink.c @@ -74,6 +74,21 @@ static const char *ext4_get_link(struct dentry *dentry, struct inode *inode, struct delayed_call *callback) { struct buffer_head *bh; + char *inline_link; + + /* + * Create a new inlined symlink is not supported, just provide a + * method to read the leftovers. + */ + if (ext4_has_inline_data(inode)) { + if (!dentry) + return ERR_PTR(-ECHILD); + + inline_link = ext4_read_inline_link(inode); + if (!IS_ERR(inline_link)) + set_delayed_call(callback, kfree_link, inline_link); + return inline_link; + } if (!dentry) { bh = ext4_getblk(NULL, inode, 0, EXT4_GET_BLOCKS_CACHED_NOWAIT); -- 2.35.1