Received: from out30-101.freemail.mail.aliyun.com (out30-101.freemail.mail.aliyun.com [115.124.30.101]) (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 5143915625A for ; Wed, 18 Dec 2024 07:36:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.101 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734507407; cv=none; b=jhAEZ0yvMhwDk0Gud3KHq5Q9de1UUbfjR+/gV6JiuzHxFO4/VovVDfvaT7iTEvwm8VPi0Nihc9+owSzK3BV2tYotQuPTSMeCR7FAHYZK1oYiwwJ12oPfWKgzNeUQIgu694esFLJ0MmzrwutHRZGIIolDiaVX0Fn0fsrV0HGA5M8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734507407; c=relaxed/simple; bh=H5wJxQbdgVmzSO6gqpg/YPkvdD7MhDt35bCQkitux6U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=HWzzrHvvSjXCM40neezSt+Grh+UZYB/lAtLQCIU5SQmgQr3LCOkB6BC26gYbt8mIhJUNjzCv+AKG3D5MlR0QLE4jug5kkmY1E18KYgkTlw8LMOZy1YJTs3Ht0WATFl9uDK2KRXOFuRGlwiFbkfjhG2rheIs5CKUUuXLz+GbB9u8= 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=rzNk9VO9; arc=none smtp.client-ip=115.124.30.101 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="rzNk9VO9" DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1734507397; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; bh=C6SFRZmapnCYvwoYSqDG1gSPBIM07eww0nEzgiLdLIk=; b=rzNk9VO9VMEVMVWDDbMjZGcJodZ2/1D0q14wbvvCQUWozxwpgPKq/cH34zbovk9qZxBvYLkJTjA25MQDxp80AybVmq2splMxrICk8JhzfyuPREteiqGh441eqJn+6UW67VvHA3uyGuA8rUWDBxQj7qDBUNQyxmrNIviwUjr0C0I= Received: from x31i01179.sqa.na131.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0WLlonKt_1734507395 cluster:ay36) by smtp.aliyun-inc.com; Wed, 18 Dec 2024 15:36:36 +0800 From: Gao Xiang To: stable@vger.kernel.org, gregkh@linuxfoundation.org Cc: allison.karlitskaya@redhat.com, linux-erofs@lists.ozlabs.org, Gao Xiang , Colin Walters Subject: [PATCH 5.10.y 2/2] erofs: fix incorrect symlink detection in fast symlink Date: Wed, 18 Dec 2024 15:36:26 +0800 Message-ID: <20241218073626.454638-2-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20241218073626.454638-1-hsiangkao@linux.alibaba.com> References: <20241218073626.454638-1-hsiangkao@linux.alibaba.com> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit commit 9ed50b8231e37b1ae863f5dec8153b98d9f389b4 upstream. 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’t need to trigger another I/O for symlink data. However, currently 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 Reported-by: https://honggfuzz.dev/ Link: https://lore.kernel.org/r/bb2dd430-7de0-47da-ae5b-82ab2dd4d945@app.fastmail.com Fixes: 431339ba9042 ("staging: erofs: add inode operations") [ Note that it's a runtime misbehavior instead of a security issue. ] Link: https://lore.kernel.org/r/20240909031911.1174718-1-hsiangkao@linux.alibaba.com [ Gao Xiang: fix 5.10.y build warning due to `check_add_overflow`. ] Signed-off-by: Gao Xiang --- 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 93a4ed665d93..60b4c4326dae 100644 --- a/fs/erofs/inode.c +++ b/fs/erofs/inode.c @@ -198,11 +198,14 @@ static int erofs_fill_symlink(struct inode *inode, void *data, unsigned int m_pofs) { struct erofs_inode *vi = EROFS_I(inode); + loff_t off; char *lnk; - /* if it cannot be handled with fast symlink scheme */ - if (vi->datalayout != EROFS_INODE_FLAT_INLINE || - inode->i_size >= PAGE_SIZE || inode->i_size < 0) { + m_pofs += vi->xattr_isize; + /* check if it cannot be handled with fast symlink scheme */ + if (vi->datalayout != EROFS_INODE_FLAT_INLINE || inode->i_size < 0 || + check_add_overflow((loff_t)m_pofs, inode->i_size, &off) || + off > i_blocksize(inode)) { inode->i_op = &erofs_symlink_iops; return 0; } @@ -211,17 +214,6 @@ static int erofs_fill_symlink(struct inode *inode, void *data, if (!lnk) return -ENOMEM; - m_pofs += vi->xattr_isize; - /* inline symlink data shouldn't cross page boundary as well */ - if (m_pofs + inode->i_size > PAGE_SIZE) { - kfree(lnk); - erofs_err(inode->i_sb, - "inline data cross block boundary @ nid %llu", - vi->nid); - DBG_BUGON(1); - return -EFSCORRUPTED; - } - memcpy(lnk, data + m_pofs, inode->i_size); lnk[inode->i_size] = '\0'; -- 2.43.5