From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f43.google.com (mail-wm1-f43.google.com [209.85.128.43]) (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 8D5ED3368A9 for ; Wed, 6 May 2026 15:03:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778079831; cv=none; b=qFT+NKA5y7Cj95lk+DNfyky6nBkGDXWyscU7XU7LtcWgJFPJhmBJZxmhYIueJndFIDBhhdMs9ndXE+GML0xrVeNU0x1jEWIwfYBxDWXhG2ivhd1wGol77LoIXJheSKE3ggvb2LQVkOCTStnaST+qboGLQQQScz3es3ydyrEWg9A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778079831; c=relaxed/simple; bh=Ct1xfBRKSQ/KPsXPmmNT+q/a4D3C9TqoNeH2NmQsQFg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QscldVTfppznewK6iyjCrVarL4sYI9yILCSyFH0YyMjmqJsbQzN4/JFtCW7WGMJnLI+f40JbveZoyyozDtB2fJeOFxn1zMulcT7APJSqVK+/O3AxZP/YQihJGbv5uJveQqxcUIQDohF/Q97HLiF2uADarkyGcUyytrl/p2eKcG8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=FwyJ3F0T; arc=none smtp.client-ip=209.85.128.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="FwyJ3F0T" Received: by mail-wm1-f43.google.com with SMTP id 5b1f17b1804b1-4896c22fcbaso50805265e9.0 for ; Wed, 06 May 2026 08:03:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1778079828; x=1778684628; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=6lCUuXDcwuMuvkw++7nOHtFX8FGwzsSx+p3o4zIoa/I=; b=FwyJ3F0TslGxoMjJcMf7GR/4+b6d5bsG7xZtL/j6dObMuAdpcIQmil4jrTkBNN68Lv HBobsElegOOLp7HRdmXS6HH3FPPLJTxUu7JV3NswJDRwnqKxfNcTMMijA+7i7A/0gZrY aLrcOJysaabkjZtta32H02Kbfw8Qr0JU1pwAx2o9ipSN+9oA05/RV2nikVEmAfEZ8cmM UioVmb0BLAx7Gbs/DTq8r3FZWrx+V4ZH1TW+q6AlX6zZOD9f0Lq3qlEYIQuxEJd3TUi4 MmI9/C++LDKQyvzQdENnZhGZ1rRk38xoC2XExfbGisJVO/Sh/FiO+hZZP5IJ7vGSBN13 sEoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778079828; x=1778684628; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6lCUuXDcwuMuvkw++7nOHtFX8FGwzsSx+p3o4zIoa/I=; b=kAVfDATQopRzRQbjJ50f8soaqArZ2o1eY/ra7ZL7/unmqnhk9jdXPn5v4RmraG9lFz +n24WBy5zaGwtlI2Eai9IqtCoSkWU1V62O4qW+8NO3nc00Pj0Yb07BJXepnQkp/SoWhC AdkWXvlZVDC0F4Oc34e0mpjUj2KYMwIxmYrwb9QpaTymP1ec/4hmRuVMCuNIEO4Wuc1g 5W/t+k1HfeJXf6zhMag8cgPI4rP4Zoi+nSN5Vxv2Gr/Fp6b+eFHBsu9nxKeiCqLx/biH S2Hyu509tzxkBqPfu7XwTStY7sDfnPhJfXh2rgUpIsMq4+Muo3MTmnIe290DLjCCCw72 jjMQ== X-Forwarded-Encrypted: i=1; AFNElJ/yHf/5UAZS0Db067mAWHtzTlrnlR4ej+CBBWeQTZdYuhI0i8SR6flPSipWzy/SjQU7tnAo/F9LRsKRL0A=@vger.kernel.org X-Gm-Message-State: AOJu0Yx2ErFCybKz1bG0vNBsqFcf+yVXt9c1eIu+qEvKZSu/czajT8ss jhuAnrFczKWnxhnuJdf7HKacvxnVe110cOUAJDa7XHab2BNAEYL8BEkad8c4rSKxlg== X-Gm-Gg: AeBDieto7mg07+WiIeyYmjLmb9dFSf699bP9XwOOfKSj5lzSPx4mYbuKEpg6EhpMJ0S dhXv0Nh2ZRTF/biJ2h95Wfo7gBNVLxtXZXEOxoB4O+ZEcGj0lODA1xuikxm7peCPChYgV4TYjVE eH1dDNaIQzU0WGrUZ18BhJUTY299lxzo/1zkMumF0wzafRhC7Aspn8MErssL4o8TI2B7Z4CPCKq ijtGwu7Pi8QPGZ8Tuiuzgh/0J0iWU5KZSDS2aIrPHxWQwc08DtTCKLPlEhJGETYBG9iT/Pq8bPh UV0wqBTI1Puzq9ngJT0Ws2kj/tn9F66gd6opD2YSY1LvR2DXj9KKLmi1jt0tMbYVi9zQgdMwVmt j61H7zsG+HIDERKui47ygA+rrw3DZStWr+7falNt1cEOWzLYJoWtJLwvwFb23GdbWp8aZLAGR9w oK+9IhJ5UAtg4JCDWKe9m/zHtm1nib04r2UhKqdkXAjsNE4uC6ABnEmQUfH+VCL6kVaNSyVCCBC AKytUnMVlZEeISi X-Received: by 2002:a05:600c:3e8d:b0:48a:6268:18a9 with SMTP id 5b1f17b1804b1-48e51f32797mr69446495e9.13.1778079827439; Wed, 06 May 2026 08:03:47 -0700 (PDT) Received: from google.com (197.183.140.34.bc.googleusercontent.com. [34.140.183.197]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-450524834eesm12653531f8f.4.2026.05.06.08.03.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 May 2026 08:03:46 -0700 (PDT) Date: Wed, 6 May 2026 16:03:43 +0100 From: Vincent Donnefort To: Mostafa Saleh Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, catalin.marinas@arm.com, will@kernel.org, maz@kernel.org, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, tabba@google.com Subject: Re: [PATCH] KVM: arm64: Harden clock for nvhe/pKVM Message-ID: References: <20260430103724.2151625-1-smostafa@google.com> 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: <20260430103724.2151625-1-smostafa@google.com> On Thu, Apr 30, 2026 at 10:37:24AM +0000, Mostafa Saleh wrote: > Sashiko(locally) reports possiblity of division by zero and > out-of-bounds bitwise shift in trace_clock_update(). > > Although the clock update is untrusted, we should at least have some > basic checks to avoid the clock value getting out of sync if the host > is buggy. I am not sure about the gain here. The host can still write values that will make it out of sync anyway. The timestamp is ultimately fed and read by the host. > > Signed-off-by: Mostafa Saleh > --- > arch/arm64/kvm/hyp/nvhe/clock.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/arch/arm64/kvm/hyp/nvhe/clock.c b/arch/arm64/kvm/hyp/nvhe/clock.c > index 32fc4313fe43..a7fc61976fd0 100644 > --- a/arch/arm64/kvm/hyp/nvhe/clock.c > +++ b/arch/arm64/kvm/hyp/nvhe/clock.c > @@ -35,6 +35,9 @@ void trace_clock_update(u32 mult, u32 shift, u64 epoch_ns, u64 epoch_cyc) > struct clock_data *clock = &trace_clock_data; > u64 bank = clock->cur ^ 1; > > + if (!mult || shift >= 64) > + return; > + > clock->data[bank].mult = mult; > clock->data[bank].shift = shift; > clock->data[bank].epoch_ns = epoch_ns; > -- > 2.54.0.545.g6539524ca2-goog >