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 CEA7D345747; Tue, 26 Aug 2025 14:17:19 +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=1756217839; cv=none; b=uaAC75UzzvVRJ7SjRR0Ux0Nj0sCYiNsF3EWCJcSZb+J4Tt0mvQzm2RTS/qDIN/NTFf8MMc7ylBxeyixkI0BHqj+b7cbAlMFTJ9ekq7ok3/YqN3WU5iuoC1vt0NjHwor1NzpooQWL+YFbZdk80G1OwwCHEqiMDD96XLmKwCThMQw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1756217839; c=relaxed/simple; bh=PoS2dp2qSrZWzq+XcTpNd//HghOCnfL23Y2PtdjDRtI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B8k68pHKaD7PtxWySWeHQrJdBA2XYEG5FRdMvtybBK/vIeNZARC7P4b5T1/qkIWhyBNMhVGqKRnmY5z33lG5XSTJYKIgxT55R7h5nu9LMT7TUPNiZ/kZ7ZwN5fIf0R6Q0sPMEMB9saCLxKOTIEFq8OpLDu+pZ8pbICSWFVemd6I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=L3re41Fz; 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="L3re41Fz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C76DC4CEF1; Tue, 26 Aug 2025 14:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1756217839; bh=PoS2dp2qSrZWzq+XcTpNd//HghOCnfL23Y2PtdjDRtI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L3re41Fzc4rIQvjEG2JVh4ZGE/QtAeIGQ9HXd49O0XXZWX1DNi6wjClEim/HGaJ1v nRvFbfiev6JNifA5BbFCLinIVCkBaAg/r7YOeD/zQhQItOiDDmeDshuXbYl76yvGoH VyP78DUvDGKbe175aThlLyVWHEeSbkean0TJ30iU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Amir Mohammad Jahangirzad , Mike Marshall , Sasha Levin Subject: [PATCH 5.10 294/523] fs/orangefs: use snprintf() instead of sprintf() Date: Tue, 26 Aug 2025 13:08:24 +0200 Message-ID: <20250826110931.700384576@linuxfoundation.org> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250826110924.562212281@linuxfoundation.org> References: <20250826110924.562212281@linuxfoundation.org> User-Agent: quilt/0.68 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 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Amir Mohammad Jahangirzad [ Upstream commit cdfa1304657d6f23be8fd2bb0516380a3c89034e ] sprintf() is discouraged for use with bounded destination buffers as it does not prevent buffer overflows when the formatted output exceeds the destination buffer size. snprintf() is a safer alternative as it limits the number of bytes written and ensures NUL-termination. Replace sprintf() with snprintf() for copying the debug string into a temporary buffer, using ORANGEFS_MAX_DEBUG_STRING_LEN as the maximum size to ensure safe formatting and prevent memory corruption in edge cases. EDIT: After this patch sat on linux-next for a few days, Dan Carpenter saw it and suggested that I use scnprintf instead of snprintf. I made the change and retested. Signed-off-by: Amir Mohammad Jahangirzad Signed-off-by: Mike Marshall Signed-off-by: Sasha Levin --- fs/orangefs/orangefs-debugfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/orangefs/orangefs-debugfs.c b/fs/orangefs/orangefs-debugfs.c index b57140ebfad0..cd4bfd92ebd6 100644 --- a/fs/orangefs/orangefs-debugfs.c +++ b/fs/orangefs/orangefs-debugfs.c @@ -354,7 +354,7 @@ static ssize_t orangefs_debug_read(struct file *file, goto out; mutex_lock(&orangefs_debug_lock); - sprintf_ret = sprintf(buf, "%s", (char *)file->private_data); + sprintf_ret = scnprintf(buf, ORANGEFS_MAX_DEBUG_STRING_LEN, "%s", (char *)file->private_data); mutex_unlock(&orangefs_debug_lock); read_ret = simple_read_from_buffer(ubuf, count, ppos, buf, sprintf_ret); -- 2.39.5