Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp1139659lqp; Fri, 22 Mar 2024 06:49:07 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWqWLJnIxYZ/FbjOZZOOHLZ2d0Qmbd7nM5d7mwdhQvbTltVElpZYglV/emkd/13BsMurzPoXmtOwTu/8BlK5KeX+Z/BOhtoVsB9VAxDbA== X-Google-Smtp-Source: AGHT+IG9fIVyK9tvsYXxxicZXKeBFVUEt+yMdtBHNUSFCyQMgAN57Q+QuhMafUoZxC02s4tqDK/t X-Received: by 2002:a05:6214:242b:b0:696:5aa2:814d with SMTP id gy11-20020a056214242b00b006965aa2814dmr2647755qvb.26.1711115346932; Fri, 22 Mar 2024 06:49:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711115346; cv=pass; d=google.com; s=arc-20160816; b=ZVQ4ugIipx/Y3DEFGUXAYMZ5J5k3oZUbaZl668OLhQ4Js0NF8AbXiFSWxeFAii6LAD XwV0uLTdza/31S66nlXEZJEjphuDMJEAuuQBUBLSMDLsvouxFbMKRcKBpfiDcdzdJmjA 8kfxi6EA+aNWT73vUR3Cj8224uw30sjc2w6SihHtagUSPHHHhR9Z7uPNYeBmy3uWqedM 3oj0GOWsNwPYKZqpE4/jUlIu6s3FKTZlyKOfe6ipY4VGVcC7iTxOAd+N+8qfockA9Erg Xg1AVtI5cUQJdGhU9dmGSAjYJDxICtBOEekWEi0lmuAyMWKTTQDG3nRNPUfh3zREkcVB yFmA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature:dkim-signature:dkim-signature :dkim-signature; bh=JjWNqh0BkyOCCMNPmezPMFuAxfGBQAC8pqGatNt+amw=; fh=vaNzcrivDnqgCiJh6fY25hmp6mkC36atbcj6sNmwiMA=; b=qu6ETLuwcU6wAsbFidi1tT48SSJd0wlGt/Pwq5jSB1/0Zax9ys87GgoVlVI7edFZ7l ibCe3mS/7l5qnCuXU5WEfweb48qBeRBfVqXzfb4tj3dTczUN0e+gq3tRXrBnlVq1ur0j YlYkjhV21eyWO15QcSmVbfeEXvJG8IkclDEUE4lx5lnBeNiossdXWdKiLtL2zUNGRAOT q1g5d+d3Q3WtpXcG8s2Iq8OSDhhhEYHUz1FnhCXJ2vgkHztBvsndk/g9JQVDUAtcTh1b zvcoCBFpzMkg3l8ZAGOknN9/WZ9Woxyph1BDKnBnIG9aNxFsjkCDcvTMgW2QcrzV8gzq Irjw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Vr6aV579; dkim=neutral (no key) header.i=@suse.cz; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Vr6aV579; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-111567-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111567-linux.lists.archive=gmail.com@vger.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 pt9-20020a056214048900b006936512bb59si1990286qvb.593.2024.03.22.06.49.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Mar 2024 06:49:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-111567-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=@suse.cz header.s=susede2_rsa header.b=Vr6aV579; dkim=neutral (no key) header.i=@suse.cz; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Vr6aV579; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519; arc=pass (i=1 spf=pass spfdomain=suse.cz dkim=pass dkdomain=suse.cz dkim=pass dkdomain=suse.cz); spf=pass (google.com: domain of linux-kernel+bounces-111567-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-111567-linux.lists.archive=gmail.com@vger.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 9A1EA1C21847 for ; Fri, 22 Mar 2024 13:49:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CC0EF45BFF; Fri, 22 Mar 2024 13:49:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="Vr6aV579"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="bB6Ml0sq"; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b="Vr6aV579"; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b="bB6Ml0sq" Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A234B2770C for ; Fri, 22 Mar 2024 13:48:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=195.135.223.130 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711115339; cv=none; b=mNRo8HbR/qxUPC+B+5Tqtix6Kq3jiJteAS1YgDjauQS2ROo6P9hMb0KM+ZUyHuLNWmNFD+yVLXGPaJfBogn4I+ET4Z/5AQSO/+xp6tUqRo3K5LY/s3FbygpAdayMkCw+REKJtz6l8jmdncgfpInHjIxTbZV/LPzRI0TaT4tqxQU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711115339; c=relaxed/simple; bh=KmWbmP2TvwHLwYxWeKmKtpn0ICKMK2xz5SBZE2FSF2E=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=eW639bTBO/tzDXp9dtXWJhxbfZLZxKx0Q7YAzsCZhKik8VJWMAMk/G2hMF/TjMO2s6tieeXOAsJwdoO6NAmfawN3KRpWmA7mTkcGCWWvDt+bE5hUz+4fKM0H3zV0OmBJuvl+BD6hGXL6eT+0DdrX6ZfGeSraw1PZr0QCHgu+V+s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz; spf=pass smtp.mailfrom=suse.cz; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=Vr6aV579; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=bB6Ml0sq; dkim=pass (1024-bit key) header.d=suse.cz header.i=@suse.cz header.b=Vr6aV579; dkim=permerror (0-bit key) header.d=suse.cz header.i=@suse.cz header.b=bB6Ml0sq; arc=none smtp.client-ip=195.135.223.130 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.cz Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id A0B8A33CC7; Fri, 22 Mar 2024 13:48:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1711115335; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JjWNqh0BkyOCCMNPmezPMFuAxfGBQAC8pqGatNt+amw=; b=Vr6aV579OgabDCFlYUVYuEFCT3+NiCAA6M/D5t23xfbidStNQRkHKy9QNcG0nSrXP86nUD +atkpKNOJjWvjhQ875+kTQ/d6pU/h+x/z3q2P9l8R2wNU01a5hmrraK+sVzvVczHd3puLQ f90wbgT2ewo97/YDZZiqVkyHFaver/U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1711115335; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JjWNqh0BkyOCCMNPmezPMFuAxfGBQAC8pqGatNt+amw=; b=bB6Ml0sqzHP/YMSDJlJ1/S+iixI8lLcOGwPNwCwrv7F4nrWKHPf/Af3Qss0Xu+XWOzyGhp 5N5JeqdK7dO+5GDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1711115335; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JjWNqh0BkyOCCMNPmezPMFuAxfGBQAC8pqGatNt+amw=; b=Vr6aV579OgabDCFlYUVYuEFCT3+NiCAA6M/D5t23xfbidStNQRkHKy9QNcG0nSrXP86nUD +atkpKNOJjWvjhQ875+kTQ/d6pU/h+x/z3q2P9l8R2wNU01a5hmrraK+sVzvVczHd3puLQ f90wbgT2ewo97/YDZZiqVkyHFaver/U= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1711115335; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=JjWNqh0BkyOCCMNPmezPMFuAxfGBQAC8pqGatNt+amw=; b=bB6Ml0sqzHP/YMSDJlJ1/S+iixI8lLcOGwPNwCwrv7F4nrWKHPf/Af3Qss0Xu+XWOzyGhp 5N5JeqdK7dO+5GDw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 95D2F136AD; Fri, 22 Mar 2024 13:48:55 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id qSuOJEeM/WX+IwAAD6G6ig (envelope-from ); Fri, 22 Mar 2024 13:48:55 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 4B884A0806; Fri, 22 Mar 2024 14:48:55 +0100 (CET) Date: Fri, 22 Mar 2024 14:48:55 +0100 From: Jan Kara To: Roman Smirnov Cc: Jan Kara , linux-kernel@vger.kernel.org, Sergey Shtylyov , Karina Yankevich , lvc-project@linuxtesting.org Subject: Re: [PATCH] udf: udftime: prevent overflow in udf_disk_stamp_to_time() Message-ID: <20240322134855.qm2pzjvvagufgrbk@quack3> References: <20240322090145.11175-1-r.smirnov@omp.ru> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240322090145.11175-1-r.smirnov@omp.ru> X-Spam-Level: Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.cz header.s=susede2_rsa header.b=Vr6aV579; dkim=pass header.d=suse.cz header.s=susede2_ed25519 header.b=bB6Ml0sq X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Spamd-Result: default: False [-1.05 / 50.00]; RCVD_VIA_SMTP_AUTH(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; TO_DN_SOME(0.00)[]; RCPT_COUNT_FIVE(0.00)[6]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[suse.cz:+]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-0.04)[58.21%]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:dkim,suse.com:email]; FUZZY_BLOCKED(0.00)[rspamd.com]; MID_RHS_NOT_FQDN(0.50)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -1.05 X-Rspamd-Queue-Id: A0B8A33CC7 X-Spam-Flag: NO On Fri 22-03-24 12:01:45, Roman Smirnov wrote: > 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. It is necessary > to convert the type of expression to 64-bit. > > Found by Linux Verification Center (linuxtesting.org) with Svace. > > Suggested-by: Sergey Shtylyov > Signed-off-by: Roman Smirnov > Reviewed-by: Sergey Shtylyov Thanks for the fix but I think this is not the right way to solve the problem. Mainly because the 64-bit division is unnecessarily costly. I'd rather first make sure that src.centiseconds < 100, src.hundredsOfMicroseconds < 100, src.microseconds < 100 (just ignore the values if any is bogus) and then do the multiplication without worrying it might overflow the int type... Honza > @@ -46,13 +47,13 @@ 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 + > + nsec = 1000LL * (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; > + dest->tv_nsec = do_div(nsec, NSEC_PER_SEC); > } > > void > -- > 2.34.1 > -- Jan Kara SUSE Labs, CR