From mboxrd@z Thu Jan 1 00:00:00 1970 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 B14851474B2; Fri, 6 Dec 2024 15:15:11 +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=1733498111; cv=none; b=Nh7iiXmGUEUBdFnNEV+ctmHavXE3HTyJ7jm5L0eLjZnPw0eOZA908hKPO62cMqrIkSLoDTwITd8l5ivG7EpRMC3YSKv5WR2fReRLgnbWi9EamojchjkIm9Rg8C3sVHT+MqbTwI5DHVNq/LrPdT01LJwde0RIowIMXanOi3XpZts= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733498111; c=relaxed/simple; bh=C6vb4Hz0U5NQfZAWolrHn6j1kUTJxab9/LWrIVevRI0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YW79kmQ5+LU8KQ7Q50SjFh/i7lt2IK7kcTXut8zAODXGZQyP/YgSB1rTUDmaxA4UjJQKnj0zsPSdtL3xLXe4zZeiCaJvremqVZ29ib6FU+P5GQmQWAqsO5dE06IEHhY+04516rGbsuI4jD556MNLJW8xj4GJehMr26ITRKxys2g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=sM2Pmph8; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="sM2Pmph8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6E66C4CED1; Fri, 6 Dec 2024 15:15:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1733498111; bh=C6vb4Hz0U5NQfZAWolrHn6j1kUTJxab9/LWrIVevRI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sM2Pmph8ViF2Rg6knk7DKsEJN9Ql6QVsmpzPliJq1R7IohM/rQjca2nl7njVx3+Dk vAEkO8nXdH+azxE1bGI4uUqQmNOBtMUa8MdixcybVROz+qZfMto0fojj9g/9aq3ahH 75DYr3i5AjFGUYeG6xkZ1T7zshUBcOUMijMtuZKo= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, lei lu , Dave Chinner , "Darrick J. Wong" , Chandan Babu R , Bin Lan Subject: [PATCH 6.6 448/676] xfs: add bounds checking to xlog_recover_process_data Date: Fri, 6 Dec 2024 15:34:27 +0100 Message-ID: <20241206143710.867866211@linuxfoundation.org> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241206143653.344873888@linuxfoundation.org> References: <20241206143653.344873888@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: lei lu commit fb63435b7c7dc112b1ae1baea5486e0a6e27b196 upstream. There is a lack of verification of the space occupied by fixed members of xlog_op_header in the xlog_recover_process_data. We can create a crafted image to trigger an out of bounds read by following these steps: 1) Mount an image of xfs, and do some file operations to leave records 2) Before umounting, copy the image for subsequent steps to simulate abnormal exit. Because umount will ensure that tail_blk and head_blk are the same, which will result in the inability to enter xlog_recover_process_data 3) Write a tool to parse and modify the copied image in step 2 4) Make the end of the xlog_op_header entries only 1 byte away from xlog_rec_header->h_size 5) xlog_rec_header->h_num_logops++ 6) Modify xlog_rec_header->h_crc Fix: Add a check to make sure there is sufficient space to access fixed members of xlog_op_header. Signed-off-by: lei lu Reviewed-by: Dave Chinner Reviewed-by: Darrick J. Wong Signed-off-by: Chandan Babu R Signed-off-by: Bin Lan Signed-off-by: Greg Kroah-Hartman --- fs/xfs/xfs_log_recover.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c @@ -2456,7 +2456,10 @@ xlog_recover_process_data( ohead = (struct xlog_op_header *)dp; dp += sizeof(*ohead); - ASSERT(dp <= end); + if (dp > end) { + xfs_warn(log->l_mp, "%s: op header overrun", __func__); + return -EFSCORRUPTED; + } /* errors will abort recovery */ error = xlog_recover_process_ophdr(log, rhash, rhead, ohead,