From patchwork Mon Nov 27 16:17:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 119740 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp486839qgn; Mon, 27 Nov 2017 08:19:08 -0800 (PST) X-Google-Smtp-Source: AGs4zMYJrFoMFwDhOcjSPOBL9/cfntdov7Q7FegFF/xqZdJXtCXNwH8K4i/D3MfkCI7M5EiKiKe6 X-Received: by 10.99.95.143 with SMTP id t137mr38341746pgb.442.1511799548867; Mon, 27 Nov 2017 08:19:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511799548; cv=none; d=google.com; s=arc-20160816; b=eQs2rwTsHw9ykE2tZEMNqdP/U8yHXiQRdJbcHUR/qqLmP+gHRyn5ZgThQronacAZPb zlMZNSESsH6a4VLhbF7YRB89JoO1SFIdWP739wZyPC3pYPbhJWBhDJBrGuaDVzGOTbWz a8dWIY3WAs7qtcfH216u0ZuF0+hYsNyXOHFzeaJoEyqf9isS3T3+Pj++Nqq8ln3xH9RD rG6CsM9AiwyVOw7KIzRO1gVkIT/AkB428QmhbvTDGYsoWNW1ezm6C4CVr8IxyciTpVGt nTdSkpjgXkYEBNlU3ALFTOz8gHRXovUamuW1PrmzH5TY/fGunsDBs+GOy1r+ZEsG9VSj y7PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=jMDF0W5jdEJnYatO7P9mdlhNkK89J2VNSe8WclAixQs=; b=dgGe0pZMlBWdNCKyEbeLlFMvbDVel+YhSRdZ7TalpGxKYzarzT9lMhaZbIeaNUTVnT 73hkjb+x8efAyjwsAo/lUh9KeUSX8PNlfnwFICPT/umRFD7TE4T3s0zOVsoXOqcpLNFW 9W9imJ7Xh7+TwoHjyHa6r/22p4z+WmR2xNNVGjg3oAiZqmCEkBXYyRm0i6ljjTVPw8cN BFgrdx/otLeoYeb27Hoxz3lm2RMVJzjQ3Nn9D1Whc21KFe4DNTxhhi9mD575rAEIMnzF FVm5CudprFrU58hzFzRnG/m+N5eDIyt/jS86201VVEZFhKFxkZlVQ2vci0y/VakoC6Ws 9rmQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u193si12760814pgc.319.2017.11.27.08.19.08; Mon, 27 Nov 2017 08:19:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753395AbdK0QTH (ORCPT + 28 others); Mon, 27 Nov 2017 11:19:07 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:54565 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752507AbdK0QTF (ORCPT ); Mon, 27 Nov 2017 11:19:05 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue105 [212.227.15.145]) with ESMTPA (Nemesis) id 0MCID3-1eSOeu0kcr-0097O8; Mon, 27 Nov 2017 17:18:49 +0100 From: Arnd Bergmann To: "David S. Miller" Cc: Arnd Bergmann , Eric Dumazet , Willem de Bruijn , Hans Liljestrand , "Reshetova, Elena" , "Rosen, Rami" , Andrey Konovalov , Alexander Potapenko , Mike Maloney , Sowmini Varadhan , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] [net-next] packet: clarify timestamp overflow Date: Mon, 27 Nov 2017 17:17:17 +0100 Message-Id: <20171127161845.3963435-1-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 X-Provags-ID: V03:K0:R3IDutJ+Ww3R4J3wQmrXLzHQNZA6Ub69KwvOzJhLZIJeX7s+0TB KdpDG+n4iTPjSiDwgsgr1GrfhKfhjJ3DUc1aESfseCjZFaagUIWJnCYJEDMlDJcY47ebl/i ylDLa/a3ZmUodAcQmyoqUD0a9dE5+jlGWQvsEC6kBXeNwsxI0lb8Hwo6tz3bXYGn2UpHVn0 jV2wevbuTHIOCDRdZPoBA== X-UI-Out-Filterresults: notjunk:1; V01:K0:iuEQvzc8vn8=:A8VzO9yyaIUpmsdfeuJjOD waDodilSHeSnEvMlHjXzYqobso9GyZ0luWnuJONiS6IfhzKmuVvxd9KP1Q38ua0c8k9enpRh9 fVMjIy31cuYf71PwL+99CxfbEGxG19KAAZRttFft8fXSLBJZmSeXVMRSDWlL951aMMy7Utxu/ ErXF+jxvyLknPagRhVLnk83C+LFitjAGUvA3tgEZ5p4hBCMhW3KAjm0jk+5Wb/VfU/TQ+SzGB D5qIijCHHydKerDABhYAHgcMoEg9E0WqcmnPkolrwnVAtYeXvbNFVX+TVHbKPsR/7bDmXKzcP JU4XkujlNJALcZNJ+A38VBmQPuGeU3eqNmXWjXnOA51X0sbujxq3zm8XFqCbbP/LYnUQB2vIm BgEWCTcyR9/5ixesQLDj5XFLUhqML49Pr46ftrYguisY0nwNV+0gLKj9qq4MSzU7qRFakKCrO vN1vfevtEYnwKlb+apwlmMRiCPd1Ex4WCp7Z5OBIB5EpvPcaDhnSYXkufoZDh9IoZLgjEOfAC 9mZApo8sWoNWX2kPch3U/hhtROpT6ZKc6SBC5eRAmfel4kVSOcuM69n97fn2pmTYq1miypBZO G/X2D5V2+g9T7sAiTGy1DJQdqGnqchdiAWxOfHXnV0JTbfeyodHV2SMZaQNs4bvdFbmmt6tsF nf6omfjFO81SDWIg3yzwrGyxuJOiIRys5F2qWzFBVGr0TcwS0JrlkfIIFXARF+PIC0lu2uTVK o3oGU4eEYWHFRDkTs/1ocEx+7T9yjgp674hYXA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The memory mapped packet socket data structure in version 1 through 3 all contain 32-bit second values for the packet time stamps, which makes them suffer from the overflow of time_t in y2038 or y2106 (depending on whether user space interprets the value as signed or unsigned). The implementation uses the deprecated getnstimeofday() function. In order to get rid of that, this changes the code to use ktime_get_real_ts64() as a replacement, documenting the nature of the overflow. As long as the user applications treat the timestamps as unsigned, or only use the difference between timestamps, they are fine, and changing the timestamps to 64-bit wouldn't require a more invasive user space API change. Note: a lot of other APIs suffer from incompatible structures when time_t gets redefined to 64-bit in 32-bit user space, but this one does not. Signed-off-by: Arnd Bergmann --- net/packet/af_packet.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) -- 2.9.0 Acked-by: Willem de Bruijn diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c index 737092ca9b4e..7432c6699818 100644 --- a/net/packet/af_packet.c +++ b/net/packet/af_packet.c @@ -439,17 +439,17 @@ static int __packet_get_status(struct packet_sock *po, void *frame) } } -static __u32 tpacket_get_timestamp(struct sk_buff *skb, struct timespec *ts, +static __u32 tpacket_get_timestamp(struct sk_buff *skb, struct timespec64 *ts, unsigned int flags) { struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb); if (shhwtstamps && (flags & SOF_TIMESTAMPING_RAW_HARDWARE) && - ktime_to_timespec_cond(shhwtstamps->hwtstamp, ts)) + ktime_to_timespec64_cond(shhwtstamps->hwtstamp, ts)) return TP_STATUS_TS_RAW_HARDWARE; - if (ktime_to_timespec_cond(skb->tstamp, ts)) + if (ktime_to_timespec64_cond(skb->tstamp, ts)) return TP_STATUS_TS_SOFTWARE; return 0; @@ -459,13 +459,20 @@ static __u32 __packet_set_timestamp(struct packet_sock *po, void *frame, struct sk_buff *skb) { union tpacket_uhdr h; - struct timespec ts; + struct timespec64 ts; __u32 ts_status; if (!(ts_status = tpacket_get_timestamp(skb, &ts, po->tp_tstamp))) return 0; h.raw = frame; + /* + * versions 1 through 3 overflow the timestamps in y2106, since they + * all store the seconds in a 32-bit unsigned integer. + * If we create a version 4, that should have a 64-bit timestamp, + * either 64-bit seconds + 32-bit nanoseconds, or just 64-bit + * nanoseconds. + */ switch (po->tp_version) { case TPACKET_V1: h.h1->tp_sec = ts.tv_sec; @@ -805,8 +812,8 @@ static void prb_close_block(struct tpacket_kbdq_core *pkc1, * It shouldn't really happen as we don't close empty * blocks. See prb_retire_rx_blk_timer_expired(). */ - struct timespec ts; - getnstimeofday(&ts); + struct timespec64 ts; + ktime_get_real_ts64(&ts); h1->ts_last_pkt.ts_sec = ts.tv_sec; h1->ts_last_pkt.ts_nsec = ts.tv_nsec; } @@ -836,7 +843,7 @@ static void prb_thaw_queue(struct tpacket_kbdq_core *pkc) static void prb_open_block(struct tpacket_kbdq_core *pkc1, struct tpacket_block_desc *pbd1) { - struct timespec ts; + struct timespec64 ts; struct tpacket_hdr_v1 *h1 = &pbd1->hdr.bh1; smp_rmb(); @@ -849,7 +856,7 @@ static void prb_open_block(struct tpacket_kbdq_core *pkc1, BLOCK_NUM_PKTS(pbd1) = 0; BLOCK_LEN(pbd1) = BLK_PLUS_PRIV(pkc1->blk_sizeof_priv); - getnstimeofday(&ts); + ktime_get_real_ts64(&ts); h1->ts_first_pkt.ts_sec = ts.tv_sec; h1->ts_first_pkt.ts_nsec = ts.tv_nsec; @@ -2184,7 +2191,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, unsigned long status = TP_STATUS_USER; unsigned short macoff, netoff, hdrlen; struct sk_buff *copy_skb = NULL; - struct timespec ts; + struct timespec64 ts; __u32 ts_status; bool is_drop_n_account = false; bool do_vnet = false; @@ -2312,7 +2319,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, skb_copy_bits(skb, 0, h.raw + macoff, snaplen); if (!(ts_status = tpacket_get_timestamp(skb, &ts, po->tp_tstamp))) - getnstimeofday(&ts); + ktime_get_real_ts64(&ts); status |= ts_status;