[Devel] [PATCH RHEL7 COMMIT] ms/drop_monitor: Make timestamps y2038 safe

Konstantin Khorenko khorenko at virtuozzo.com
Fri Mar 29 20:54:24 MSK 2024


The commit is pushed to "branch-rh7-3.10.0-1160.108.1.vz7.221.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1160.108.1.vz7.221.2
------>
commit 5451bbb8bf28025c258e6029a76d1f26dfdef966
Author: Ido Schimmel <idosch at mellanox.com>
Date:   Fri Aug 23 18:47:21 2019 +0300

    ms/drop_monitor: Make timestamps y2038 safe
    
    Timestamps are currently communicated to user space as 'struct
    timespec', which is not considered y2038 safe since it uses a 32-bit
    signed value for seconds.
    
    Fix this while the API is still not part of any official kernel release
    by using 64-bit nanoseconds timestamps instead.
    
    mFixes: ca30707dee2b ("drop_monitor: Add packet alert mode")
    mFixes: 5e58109b1ea4 ("drop_monitor: Add support for packet alert mode for hardware drops")
    Signed-off-by: Ido Schimmel <idosch at mellanox.com>
    Acked-by: Neil Horman <nhorman at tuxdriver.com>
    Signed-off-by: David S. Miller <davem at davemloft.net>
    
    Backporting to vz7 kernel note:
     * net_dm_hw_*() hunks have been dropped, no Hardware Node functionality
       in vz7 kernel
    
    https://virtuozzo.atlassian.net/browse/PSBM-153598
    (cherry picked from commit bd1200b79510a68554890af2f48d92be6eb1daf8)
    Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
---
 include/uapi/linux/net_dropmon.h | 2 +-
 net/core/drop_monitor.c          | 7 +++----
 2 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/include/uapi/linux/net_dropmon.h b/include/uapi/linux/net_dropmon.h
index 9823d47341c3..c00b874da97b 100644
--- a/include/uapi/linux/net_dropmon.h
+++ b/include/uapi/linux/net_dropmon.h
@@ -70,7 +70,7 @@ enum net_dm_attr {
 	NET_DM_ATTR_PC,				/* u64 */
 	NET_DM_ATTR_SYMBOL,			/* string */
 	NET_DM_ATTR_IN_PORT,			/* nested */
-	NET_DM_ATTR_TIMESTAMP,			/* struct timespec */
+	NET_DM_ATTR_TIMESTAMP,			/* u64 */
 	NET_DM_ATTR_PROTO,			/* u16 */
 	NET_DM_ATTR_PAYLOAD,			/* binary */
 	NET_DM_ATTR_PAD,
diff --git a/net/core/drop_monitor.c b/net/core/drop_monitor.c
index 65ce1cadd348..30d6f8f6ccb8 100644
--- a/net/core/drop_monitor.c
+++ b/net/core/drop_monitor.c
@@ -332,7 +332,7 @@ static size_t net_dm_packet_report_size(size_t payload_len)
 	       /* NET_DM_ATTR_IN_PORT */
 	       net_dm_in_port_size() +
 	       /* NET_DM_ATTR_TIMESTAMP */
-	       nla_total_size(sizeof(struct timespec)) +
+	       nla_total_size(sizeof(u64)) +
 	       /* NET_DM_ATTR_PROTO */
 	       nla_total_size(sizeof(u16)) +
 	       /* NET_DM_ATTR_PAYLOAD */
@@ -366,7 +366,6 @@ static int net_dm_packet_report_fill(struct sk_buff *msg, struct sk_buff *skb,
 	u64 pc = (u64)(uintptr_t) NET_DM_SKB_CB(skb)->pc;
 	char buf[NET_DM_MAX_SYMBOL_LEN];
 	struct nlattr *attr;
-	struct timespec ts;
 	void *hdr;
 	int rc;
 
@@ -386,8 +385,8 @@ static int net_dm_packet_report_fill(struct sk_buff *msg, struct sk_buff *skb,
 	if (rc)
 		goto nla_put_failure;
 
-	if (ktime_to_timespec_cond(skb->tstamp, &ts) &&
-	    nla_put(msg, NET_DM_ATTR_TIMESTAMP, sizeof(ts), &ts))
+	if (nla_put_u64_64bit(msg, NET_DM_ATTR_TIMESTAMP,
+			      ktime_to_ns(skb->tstamp), NET_DM_ATTR_PAD))
 		goto nla_put_failure;
 
 	if (!payload_len)


More information about the Devel mailing list