Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp246861lqr; Wed, 5 Jun 2024 05:07:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUZkLwA6zvyUDaD+xKrKgwc/jvnHDs/dRoVKwDgsHkk5v0vBLnyGYV/XR35eyLQpyyXOx/R+OhOysjC4y5isZM+NB+o1IMcyLlsZI/2lA== X-Google-Smtp-Source: AGHT+IGkLcdlDTdXt3GweMaqCzRgTmUKyrEFziMjbncBXTTG7ojLvD5yGr5OtmPhJG8Czx9HpsZJ X-Received: by 2002:a05:6e02:1a09:b0:374:ae97:9066 with SMTP id e9e14a558f8ab-374b1eff4f4mr24830305ab.17.1717589268771; Wed, 05 Jun 2024 05:07:48 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717589268; cv=pass; d=google.com; s=arc-20160816; b=hUuboCzjb066yvn8OPWUoKTDhXluW38yl29cNfNOLt7w0eiDZRb4g0bOGj+hEubZK4 3h5IlgBBDFplDrgkdNQzsvy0gwiKwg+FadJ5FPyVEKOD5N3jFhNbI1G9B4DlOSxQ+sGK EM6R91vlgKWjCS6LvG0oQ01DBHLf6MbjMDBuXQRGs5v+IhzSxi1BLO5XoZzdl5M17z3S td8ABKvEw7862KoAw04i1+8dgmy2aJx+yqMGYIBcndw1dAuPioIgb8I/oQNnr0CPcUjV hgELOqg71tsb9EQjYlKdcRMi8LiTB46fZKPJBckNYTS5D9FuhHQLdvnHyRjBk3mcmCMG 9MJg== 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=ybGTd8jkhGx44JDNFr19UODlOhx+b9yI7dKFvTQNFeg=; fh=Xjd/OQkm2jBpNVqU6zus7zzmXvF2+eN3fdKj9IAAs8U=; b=Sm2hXdpRDdFhQQuY/OXLo0RZXodOSkM6inAmqQ5rTT1EZ8jrIoPGj9Ojf8uAtY3ECY cS2bXxfgm1tpShIzhfdh+v55ykmNxhwNOnRL4uqeig2VvO36MPQ5gdXW9NxrbrVLNUlY xUkYYrh0hTKTfOcgfmhYMkNtYOR1pMJRLTRudNBbVwl21eF7BsXKYJuGGJLxGQuuSZ28 sCEM+ecHUR2USI38jOcPE8tsdgDA7yHo5GKDEQQeqM6szrwNZQc1JV/k7Eyf4V2RmWjs 7tDnc2FvyXy40BUThmP5eUMeWppSIUlnovT02dyT6OCQ8xCWWWMoX8I+KEZInKKuUouo qY5Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=daTZsFwp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202305-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202305-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c3551558d4si9819667a12.198.2024.06.05.05.07.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 05:07:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202305-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=daTZsFwp; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202305-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202305-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 92C7028D701 for ; Wed, 5 Jun 2024 11:51:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 298D4195FE5; Wed, 5 Jun 2024 11:49:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="daTZsFwp" 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 49AEA19923F; Wed, 5 Jun 2024 11:49:45 +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=1717588186; cv=none; b=CTGIxzuAcGRtLtmbfwhA0MksrnNbhzaqg6Xn3fVbCFzeMiieobX1kFNUE39XccIM4G2bD1x/nj2n20rV48bIMpU+L7faYKfjrE3JPsR9iHUOP08o1qg/DwN/7rOidcB0ZpkeRvZmq+DQUjVzCayNXOK+gXPT3aCycIOgYiivhFc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717588186; c=relaxed/simple; bh=klJFbPZVKDRnhHyoOzh54fT6kOqFxXYc3De6rLdD1aE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bTSaMUVP0objVWD18cmf593sxaKAYldgkEeu6GJk76bC/0mjjMZxwP4iWuO+s24q301tHC4GqJ76RjG4U3uyVPC8gVywd42deRlgN2JzkC+uz+skC0Z2ao43zSc8wdxJ8YmKllradxNWikbTacO2obCsiIlsKKz6BBtuyF5uXjM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=daTZsFwp; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 04823C32786; Wed, 5 Jun 2024 11:49:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717588185; bh=klJFbPZVKDRnhHyoOzh54fT6kOqFxXYc3De6rLdD1aE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=daTZsFwpmyzWzLFo2K1sNj9B7L6J93kr0Lj/bviJ4aNJ8mhiWFuK+x1QLMuWGFwjQ uLmrnpNE83b/Cx1MGz/QNbMmfQh4Pou02Xeq6GrVPGWsWMLwSccKUfSNnSbcJ83k8K 0V4lBNK1ZeIKvmmGem2/BddlvkO3l2EUYu7o9dYojdESnNkF5YUamrC8OI8yPumOsz l995sr8MHctj37949mIWSvIIqh4QgTk3QYTJ1pIMFY3SkjTnw0kIj42tOdsZJN5Myw DMakFeMTw7Ghtub1h8RX8VFS9YWmlrq9+01L2/LR+5Oy3r7YaUJgmOGJuiFkVDCoVR W4ltzf+EWm1BQ== 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 6.9 09/28] udf: udftime: prevent overflow in udf_disk_stamp_to_time() Date: Wed, 5 Jun 2024 07:48:38 -0400 Message-ID: <20240605114927.2961639-9-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605114927.2961639-1-sashal@kernel.org> References: <20240605114927.2961639-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 6.9.3 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 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