From nobody Sat Nov 30 16:33:27 2024 Received: from out30-100.freemail.mail.aliyun.com (out30-100.freemail.mail.aliyun.com [115.124.30.100]) (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 728A51400A for ; Mon, 9 Sep 2024 03:19:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.100 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725851962; cv=none; b=LvY7cIJ+9EU1nVp0MExPU43fv0Chvhs6vdPnQLbaJFvB6VDF3ZTFkg75kiBkgggYP/AUCxEUDySQqEcBo8jiAkJM0UUT+DvMRFJKKJma/m3qEBcHfQ7L47FWlXYDNOJ5lUSvFvLRCv7H20bXSpkXIDtA9GdSU2btYdUmUwPG+Ck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725851962; c=relaxed/simple; bh=OsrKyfi2v5wJpSQFdTckhJDKuI+HNyokIGLwr1fzFig=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MR7GUZseXKlnmv+AhkLLrgNqD+cSvMGsiSG0YLvHacF8UkNeMbMFupGrhvEc0DOFLP7MWLec9KG77GEDWrE56mfmN27gKOzgCWqj2S6lFTTLlyPNNqmeNW48MiNLbVN4tBwZ+Mq168DSm5zxtcXEgnjeJmasWs/o6rVIj8yJAiQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=QvCZNBGz; arc=none smtp.client-ip=115.124.30.100 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="QvCZNBGz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1725851956; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=f1xp5p0CJfo1Mj+ACRPp8EkDOPZ2/JavyzqzS5tmiWE=; b=QvCZNBGz4DZ6yXooswbnt+eEZuPRHRRUb8cJmU9HhNSvDbvVsYzjY2P8Cex14idFEMoFfSvdcEiLf/O1MW7lr+orv3wWu7tCpLqbOjXbKRKUhXBrYKhhdIdQPvdt5N3gqmDqK9N+zpubL8VsZt/bfcq/2CNkqMEG9Z9LN18b3HM= Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0WEWAiPT_1725851952) by smtp.aliyun-inc.com; Mon, 09 Sep 2024 11:19:16 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: LKML , Gao Xiang , Colin Walters Subject: [PATCH v2] erofs: fix incorrect symlink detection in fast symlink Date: Mon, 9 Sep 2024 11:19:11 +0800 Message-ID: <20240909031911.1174718-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240909022811.1105052-1-hsiangkao@linux.alibaba.com> References: <20240909022811.1105052-1-hsiangkao@linux.alibaba.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Fast symlink can be used if the on-disk symlink data is stored in the same block as the on-disk inode, so we don=E2=80=99t need to trigger another I/O for symlink data. However, correctly fs correction could be reported _incorrectly_ if inode xattrs are too large. In fact, these should be valid images although they cannot be handled as fast symlinks. Many thanks to Colin for reporting this! Reported-by: Colin Walters Fixes: 431339ba9042 ("staging: erofs: add inode operations") Signed-off-by: Gao Xiang Reported-by: https://honggfuzz.dev/=20 --- v2: - sent out a wrong version (`m_pofs +=3D vi->xattr_isize` was missed). fs/erofs/inode.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c index 5f6439a63af7..f2cab9e4f3bc 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -178,12 +178,14 @@ static int erofs_fill_symlink(struct inode *inode, vo= id *kaddr, unsigned int m_pofs) { struct erofs_inode *vi =3D EROFS_I(inode); - unsigned int bsz =3D i_blocksize(inode); + loff_t off; char *lnk; =20 - /* if it cannot be handled with fast symlink scheme */ - if (vi->datalayout !=3D EROFS_INODE_FLAT_INLINE || - inode->i_size >=3D bsz || inode->i_size < 0) { + m_pofs +=3D vi->xattr_isize; + /* check if it cannot be handled with fast symlink scheme */ + if (vi->datalayout !=3D EROFS_INODE_FLAT_INLINE || inode->i_size < 0 || + check_add_overflow(m_pofs, inode->i_size, &off) || + off > i_blocksize(inode)) { inode->i_op =3D &erofs_symlink_iops; return 0; } @@ -192,16 +194,6 @@ static int erofs_fill_symlink(struct inode *inode, voi= d *kaddr, if (!lnk) return -ENOMEM; =20 - m_pofs +=3D vi->xattr_isize; - /* inline symlink data shouldn't cross block boundary */ - if (m_pofs + inode->i_size > bsz) { - kfree(lnk); - erofs_err(inode->i_sb, - "inline data cross block boundary @ nid %llu", - vi->nid); - DBG_BUGON(1); - return -EFSCORRUPTED; - } memcpy(lnk, kaddr + m_pofs, inode->i_size); lnk[inode->i_size] =3D '\0'; =20 --=20 2.43.5