Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp253825lqr; Wed, 5 Jun 2024 05:19:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWdYHKlyVjyD1LElTFIwcnrSmTohSWxEiItueyAuqAaeZ+t+MYWr8U8tLxOW3+Owe0Pbg2/wgIrBDxE5e4EC4s8KfWk++JO4rhK07X0Xg== X-Google-Smtp-Source: AGHT+IGc3F0KSV9gEemXrG4CxAAvjHoXS4H6glxypb+95vqBEBXMYUprEoZLoD2fpAOqQVBIGdJQ X-Received: by 2002:a05:6870:6490:b0:24f:d147:8a24 with SMTP id 586e51a60fabf-25122a5db99mr2396245fac.51.1717589944194; Wed, 05 Jun 2024 05:19:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717589944; cv=pass; d=google.com; s=arc-20160816; b=K8zRoPX37JrqUhiExg7KBTbmkKMtqInOuVYMqp0goPmnfNHCkM4oVzQid19cynVijq na0v37LSbw//nWqSBSpbkTfwDJXyn3XDtZlFTBqa26qqA5zuHU5vR3V0ubxKBYFT7bAV EkHNJErCH52WuVqnzXeW8cTzJaSdjRIMG1CwCnw01GkHZkzZy1H242JY6hFF3GciYSVG s1CY3CuLTe8inZ9a29JJ9520V1wK7OC7jDn4iKk5vy5Y7/TXWPWcW1fgpd9bxKOVDP1S BLjErPCYQbQAORGGqxjdrbOB+0NheXIFxt902W1+wMLPtZzS7PccORfMdTBKP9I9UJRU /BSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=EddNNtFXmYK/ZbBOTNsinXDBpijxzFng3hifLuCI0/g=; fh=Xjd/OQkm2jBpNVqU6zus7zzmXvF2+eN3fdKj9IAAs8U=; b=Idy2ZSQaRVUjsUow7G3Z7aGF8K/ShRI5u68F8OG6j7IYiG+kZ5YLFJyS+JMhrYhuun 8Q+Gc60pB+EmVxsiKePuj4BaFoT/xAWMf6rnp/STaQXJjZWujfv98y+OJCPv4n7Tw6cl sjgRRjzb0Ib5IoKaFkjkETBvLTdTvpHUx1jVw76LPtgl81TLrxixsK1ELJUdWrsbt23B fAL20fSpXW5IkxDWcbpRNXHNOLzc/h+j3at0yj8LQA53sfT18PzqeGOQ70B+GEVaXZ0S 7wbOPiGLy8FTe55mTJHEh+gmWIr/rKOegNRnjJY1jK+cqByNtpc+KPDxpnWS/vrqGB0g XWJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KiNR6jl8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202415-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202415-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-794f318a1e4si235290385a.429.2024.06.05.05.19.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 05:19:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202415-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KiNR6jl8; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202415-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202415-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id DD8481C236AB for ; Wed, 5 Jun 2024 12:19:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B5D8B1BA894; Wed, 5 Jun 2024 11:55:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="KiNR6jl8" 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 DE5A51BA882; Wed, 5 Jun 2024 11:55:21 +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=1717588522; cv=none; b=Nutpb4Ta9Cqhl66bYLfm7BR94IaE7AFG7TKgFl1T0LYsv01+oryj37sLM5jDAx4IP9acuQWRgpaBCfETXsousNPiEjzboZy/eCxBUamEcTkZ/dX0RzcEBoYdp3k73oybaJ4AGKzEWlzek3jRCWLGMmII7RZqrgQoCOG5diIp9jc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588522; c=relaxed/simple; bh=vZPl2Rg9MMjHgwCnAcC6p7mvcU/vcb8ipMfTFMNDETU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KaqdxrFEPzNgaZ2geMHiJ61Zdz/4nVq8qZx6tE3CK7oYLvWn2gU8HQUeGHhvQVyhIqlcgLkOpZ049FTUqynJ+GkITRofmcLtglQj7SEwBsaPG0by0j3zWIUKX/oTjFxztnieR2iQbTnqY86o5x15wh8H8H4rMKxRYlE9olDb7+o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KiNR6jl8; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id F271EC32786; Wed, 5 Jun 2024 11:55:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717588521; bh=vZPl2Rg9MMjHgwCnAcC6p7mvcU/vcb8ipMfTFMNDETU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KiNR6jl8vm78FoYfg30mzAwmjl7R4CyOEoKr3kMu9JN0X3M345jPcVSmckWESk62z r6NsJayu2gUCRY+8/i1euvW98jjmvYcouPWEu42cWrq7YwXgQDxcCf9b0ubLPKDr01 L4nWFwRFek+fPhPH/igiANsaLfbIyJyQVW+YUwHxzFcC65Gw+tuOYF5NmuN3xepApT ILa6zxqjGj71e/bpylwhVHCcjibBFLzEUpUa+L6UafIgmevvdvzPHW9EUGIVFGXAsl m7QUvs88F/02/6C6quDV+8xpul8PrmtbRqm98OkIjRxnimviXr9sa9AWSmTUCbH1DV W6ES4tsBzpYng== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Roman Smirnov , Jan Kara , Sergey Shtylyov , Sasha Levin , jack@suse.com Subject: [PATCH AUTOSEL 4.19 2/4] udf: udftime: prevent overflow in udf_disk_stamp_to_time() Date: Wed, 5 Jun 2024 07:55:10 -0400 Message-ID: <20240605115518.2964670-2-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605115518.2964670-1-sashal@kernel.org> References: <20240605115518.2964670-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 4.19.315 Content-Transfer-Encoding: 8bit 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