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 1B58E1E3DF9; Mon, 21 Oct 2024 10:34:23 +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=1729506864; cv=none; b=jR+kgyt2xu1P6c/kMpvCoFqH0CTmzd07OBjDCDyucwxyecDxotYyIfphuKavkNNA8tAf39gdSJeAow+o/ZjY/xPTtBOiqS4oI3GFJXdRR4g+Lgh6R9sS06N6m3LKX4Sw2+m7ErABU3xjBJkV24irYAcHW8FP8snJC8WVAGLzVJc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729506864; c=relaxed/simple; bh=RlMXq/dfHd5SmCXVg9A08zt9tUjqw50i5CezNZJkWcg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p75HTgyoapfvaQgiWVYnt0P1o+nEXT2obLzfFPiVjKgLOIRA/8IbjqCKvImXrf4gZ77KD0atJ/I6t+iffMDM0d5mFNi9RtxQssZNbYQyXhlA97W4cg/JmpXa0e+xgvxjeUBYPtQ23zcQDi/n4IGpvbxXXt3pmnYKKaTz5DwuoT0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=U/A3Wx/V; 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="U/A3Wx/V" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4E300C4CEC7; Mon, 21 Oct 2024 10:34:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1729506863; bh=RlMXq/dfHd5SmCXVg9A08zt9tUjqw50i5CezNZJkWcg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U/A3Wx/VoIwW7i38TbDumoDwfMCJ6be6mjCtbGVHIY/KK8ZgSGztu2rsqe83T+e2d sEpbEZ5ih0NR7MDwtXHd2rCNb7wDv24Rf2YtWABkSQTuVAWXAAMqFdMQj7qZVVKtu+ 50x5Nny8hPv/EQ/OfCAoqkn83xiWxzrjPnFgl/K0= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Richard Cochran , Andrew Lunn , Thomas Gleixner , Jinjie Ruan , Jakub Kicinski Subject: [PATCH 6.6 011/124] posix-clock: Fix missing timespec64 check in pc_clock_settime() Date: Mon, 21 Oct 2024 12:23:35 +0200 Message-ID: <20241021102257.156117927@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241021102256.706334758@linuxfoundation.org> References: <20241021102256.706334758@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 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jinjie Ruan commit d8794ac20a299b647ba9958f6d657051fc51a540 upstream. As Andrew pointed out, it will make sense that the PTP core checked timespec64 struct's tv_sec and tv_nsec range before calling ptp->info->settime64(). As the man manual of clock_settime() said, if tp.tv_sec is negative or tp.tv_nsec is outside the range [0..999,999,999], it should return EINVAL, which include dynamic clocks which handles PTP clock, and the condition is consistent with timespec64_valid(). As Thomas suggested, timespec64_valid() only check the timespec is valid, but not ensure that the time is in a valid range, so check it ahead using timespec64_valid_strict() in pc_clock_settime() and return -EINVAL if not valid. There are some drivers that use tp->tv_sec and tp->tv_nsec directly to write registers without validity checks and assume that the higher layer has checked it, which is dangerous and will benefit from this, such as hclge_ptp_settime(), igb_ptp_settime_i210(), _rcar_gen4_ptp_settime(), and some drivers can remove the checks of itself. Cc: stable@vger.kernel.org Fixes: 0606f422b453 ("posix clocks: Introduce dynamic clocks") Acked-by: Richard Cochran Suggested-by: Andrew Lunn Suggested-by: Thomas Gleixner Signed-off-by: Jinjie Ruan Link: https://patch.msgid.link/20241009072302.1754567-2-ruanjinjie@huawei.com Signed-off-by: Jakub Kicinski Signed-off-by: Greg Kroah-Hartman --- kernel/time/posix-clock.c | 3 +++ 1 file changed, 3 insertions(+) --- a/kernel/time/posix-clock.c +++ b/kernel/time/posix-clock.c @@ -299,6 +299,9 @@ static int pc_clock_settime(clockid_t id goto out; } + if (!timespec64_valid_strict(ts)) + return -EINVAL; + if (cd.clk->ops.clock_settime) err = cd.clk->ops.clock_settime(cd.clk, ts); else