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 D96D72F25F1; Mon, 27 Oct 2025 19:14:38 +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=1761592478; cv=none; b=OAcmAjg+rH4Lkt4rye+m04ZmqZovwAESib56QK/wuCkG2bJ/NomriHGiUlt1GM11hSDuPMMYrCiL0yF1YdqU4ZPui+Iu19ZHldjSBrUcAaAltUWlhGQ9LJS1qTvNxO+5x2e1NXN/v51KBWrTNBIUP75NSg63zDRMpuGWytBJ70c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761592478; c=relaxed/simple; bh=UZAmSh27JQvQtZh+7xZ7YPtAPHev5I0k0TKwYPNn8Ac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bY1hHt/gwYbvv4AoSN5RfCuNp1O5QmUUHP+ZTG8A6rZwUSEG7THfWS6QVWTyVS3NLmvBtsqrjn4F2dwo/5D0xXRMpRTdNZZ6qIy0V1kdjoLC6JSFwlZcoHH/sRdPlSbCejUcIf3KS1vHuMtlJuNeWQEAhqffZ2R92wLVON8hq9g= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=xlQnayZ2; 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="xlQnayZ2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42F02C4CEF1; Mon, 27 Oct 2025 19:14:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1761592478; bh=UZAmSh27JQvQtZh+7xZ7YPtAPHev5I0k0TKwYPNn8Ac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xlQnayZ2HGRnAYZl+7hqAxEob0aASFqyAHt1h6HA+DNz+Z9UExwHgPNiv44kRFyPj AWofm0RmX9qFt0YqXP7NxYCCc0QN37FZsqYic1ljmZQDC8ZwVzpxigH+J5uyRbaFHA ddSDoOG/YXQn868cVvGBwAx1dlt1ZwSTJyqEqOWQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jan Kara , "Darrick J. Wong" , Theodore Tso , Sasha Levin Subject: [PATCH 6.1 136/157] ext4: avoid potential buffer over-read in parse_apply_sb_mount_options() Date: Mon, 27 Oct 2025 19:36:37 +0100 Message-ID: <20251027183504.907507690@linuxfoundation.org> X-Mailer: git-send-email 2.51.1 In-Reply-To: <20251027183501.227243846@linuxfoundation.org> References: <20251027183501.227243846@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Theodore Ts'o [ Upstream commit 8ecb790ea8c3fc69e77bace57f14cf0d7c177bd8 ] Unlike other strings in the ext4 superblock, we rely on tune2fs to make sure s_mount_opts is NUL terminated. Harden parse_apply_sb_mount_options() by treating s_mount_opts as a potential __nonstring. Cc: stable@vger.kernel.org Fixes: 8b67f04ab9de ("ext4: Add mount options in superblock") Reviewed-by: Jan Kara Reviewed-by: Darrick J. Wong Signed-off-by: Theodore Ts'o Message-ID: <20250916-tune2fs-v2-1-d594dc7486f0@mit.edu> Signed-off-by: Theodore Ts'o [ added sizeof() third argument to strscpy_pad() ] Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/ext4/super.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -2415,7 +2415,7 @@ static int parse_apply_sb_mount_options( struct ext4_fs_context *m_ctx) { struct ext4_sb_info *sbi = EXT4_SB(sb); - char *s_mount_opts = NULL; + char s_mount_opts[65]; struct ext4_fs_context *s_ctx = NULL; struct fs_context *fc = NULL; int ret = -ENOMEM; @@ -2423,15 +2423,11 @@ static int parse_apply_sb_mount_options( if (!sbi->s_es->s_mount_opts[0]) return 0; - s_mount_opts = kstrndup(sbi->s_es->s_mount_opts, - sizeof(sbi->s_es->s_mount_opts), - GFP_KERNEL); - if (!s_mount_opts) - return ret; + strscpy_pad(s_mount_opts, sbi->s_es->s_mount_opts, sizeof(s_mount_opts)); fc = kzalloc(sizeof(struct fs_context), GFP_KERNEL); if (!fc) - goto out_free; + return -ENOMEM; s_ctx = kzalloc(sizeof(struct ext4_fs_context), GFP_KERNEL); if (!s_ctx) @@ -2463,11 +2459,8 @@ parse_failed: ret = 0; out_free: - if (fc) { - ext4_fc_free(fc); - kfree(fc); - } - kfree(s_mount_opts); + ext4_fc_free(fc); + kfree(fc); return ret; }