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 81FA1146592; Tue, 25 Jun 2024 09:51:03 +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=1719309063; cv=none; b=hyrhW/k5NFFvsJiwvHmDDHr6sR6Fga8afpk+TKhtuVZRV1oTetl84F+NZQQf1eQNlxXpt88lQH+va5dbz8rtkx/35FNYiRLIZihNUR76Y+fkLIG/rj0gDWWDIKB4KKEoxQGQvdBQ6nPc0yRBWCWDZYRBTBIafwXEhLRKWy18hRQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719309063; c=relaxed/simple; bh=BC7cVSVIlVvXhaLVBwT3d0KnN+wjKfdeuswnUjzDw2A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TuLFXd514AGjhCandhmgFxHWV0A76hQNA7fPP3BImUO7aea6UdTwRWi/eXpPWEXD7WPBdjxy1iXlbqLSx4jLsTZGfChWU6nojEHb5CtpgiIWZZK0X4OBLX4cz7JELTGk0U/avIab6Qg4Ojq9SXTuR2vckOydqeRsJnwotO9XauE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=E8BWXz5b; 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="E8BWXz5b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92AFBC32781; Tue, 25 Jun 2024 09:51:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1719309063; bh=BC7cVSVIlVvXhaLVBwT3d0KnN+wjKfdeuswnUjzDw2A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E8BWXz5byN3yr6Vakxt08Mt5b7k7ia7PVGYV2NxNG90GZXEiwcsCl4MHSaHKQypcj xYJJ9LsafFzN6Es+YUz3MW7psbdcuVZgS+RAb5w/nAWCyZXgARDnOHLQvtXcCR6Nkw Jxd4uIBl/IytG6VnooFEpZT0GfyGq9GVQ5Z4UyHc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jan Kara , Roman Smirnov , Sergey Shtylyov , Sasha Levin Subject: [PATCH 6.6 051/192] udf: udftime: prevent overflow in udf_disk_stamp_to_time() Date: Tue, 25 Jun 2024 11:32:03 +0200 Message-ID: <20240625085539.128905914@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240625085537.150087723@linuxfoundation.org> References: <20240625085537.150087723@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: Roman Smirnov [ Upstream commit 3b84adf460381169c085e4bc09e7b57e9e16db0a ] An overflow can occur in a situation where src.centiseconds takes the value of 255. This situation is unlikely, but there is no validation check anywere in the code. Found by Linux Verification Center (linuxtesting.org) with Svace. Suggested-by: Jan Kara Signed-off-by: Roman Smirnov Reviewed-by: Sergey Shtylyov Signed-off-by: Jan Kara Message-Id: <20240327132755.13945-1-r.smirnov@omp.ru> Signed-off-by: Sasha Levin --- fs/udf/udftime.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/fs/udf/udftime.c b/fs/udf/udftime.c index 758163af39c26..78ecc633606fb 100644 --- a/fs/udf/udftime.c +++ b/fs/udf/udftime.c @@ -46,13 +46,18 @@ udf_disk_stamp_to_time(struct timespec64 *dest, struct timestamp src) dest->tv_sec = mktime64(year, src.month, src.day, src.hour, src.minute, src.second); dest->tv_sec -= offset * 60; - dest->tv_nsec = 1000 * (src.centiseconds * 10000 + - src.hundredsOfMicroseconds * 100 + src.microseconds); + /* * Sanitize nanosecond field since reportedly some filesystems are * recorded with bogus sub-second values. */ - dest->tv_nsec %= NSEC_PER_SEC; + if (src.centiseconds < 100 && src.hundredsOfMicroseconds < 100 && + src.microseconds < 100) { + dest->tv_nsec = 1000 * (src.centiseconds * 10000 + + src.hundredsOfMicroseconds * 100 + src.microseconds); + } else { + dest->tv_nsec = 0; + } } void -- 2.43.0