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 788DF1836EF; Wed, 3 Jul 2024 10:55:22 +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=1720004122; cv=none; b=OJWWXgUDxogsflLKh+D6zclIOhQSRnBZBZRd8EVLXsrS5O+stqW0clY6VVPODvXHq63yjgL/Q5Odl4/Oca2fQQVTwi1fVxqctZjwYBb/y4ZVRr4Ly+mwDSeutpNbpRnmwzpR1Bot0zQBvGajm0ZsCHJnWc4PpyolwRq23kwb9C8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720004122; c=relaxed/simple; bh=prOVu5KDLwQPGGiViUOcL9w20z0xvWs+MBJHUIgsu8o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tBLUQ/RuMquHLO4rGg4zmCigeqrlBXoOTis9dh3ZsC9oP9eV6+jlYfgXnQRkoY1sr7l/b3lE0fhdFAngQkpRFmiFFKY3t69e9cIUpoEuaXfkmZscf5vpPxjtOKPjvdRkDDhs/F/3wwPjyujMyAqeDdxFriAqSaHJa0glRU42lTM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=AjeBh+1e; 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="AjeBh+1e" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A24C7C2BD10; Wed, 3 Jul 2024 10:55:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1720004122; bh=prOVu5KDLwQPGGiViUOcL9w20z0xvWs+MBJHUIgsu8o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AjeBh+1eMS2SZI9tSXasrWZPZAD83k2W9XVcQQMp4NjXWzKQEA+GRn7qc03yW5s3V 4ZnUpyCI51w2DtijXBtCnFFov2qObLYCMt9HoE7Wx5ptMgGJzhTEGci+OygVP0DWXl WUgk98NacObnLBRywDehhc1jW7pWoaLDwuAH+kiY= 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 5.4 098/189] udf: udftime: prevent overflow in udf_disk_stamp_to_time() Date: Wed, 3 Jul 2024 12:39:19 +0200 Message-ID: <20240703102845.201226200@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240703102841.492044697@linuxfoundation.org> References: <20240703102841.492044697@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 5.4-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 fce4ad976c8c2..26169b1f482c3 100644 --- a/fs/udf/udftime.c +++ b/fs/udf/udftime.c @@ -60,13 +60,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