From patchwork Fri Nov 10 15:37:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 118578 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp8079936qgn; Fri, 10 Nov 2017 07:38:39 -0800 (PST) X-Google-Smtp-Source: AGs4zMbKi4OoFmZrv4Z/7dMJwxe8hO4RrlqCZWi3rV53ifJXX/jlSRqDU55K1IVN3fxzdb05vBX0 X-Received: by 10.99.121.140 with SMTP id u134mr728024pgc.16.1510328319845; Fri, 10 Nov 2017 07:38:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510328319; cv=none; d=google.com; s=arc-20160816; b=PJD74EHNazXfQfaaENIXrfcpUVjZmacirZNJ3tj0lfhui9b3ofO1uAWGwz4xM8MGgf yRE3Ly2sARULmRW9KwrjxCJyVmf0PlxyIKG0EmYjiEOis606gaSJwTnl+9oZ3D6CAEWx gfLKQSpMupHjmN+m7oUott+SlYWfcOFtU0Hxg+8BBiBvZD8wwNc5zeL1r0++ASDHduBb J6Kp71yhO8b1Z9CgkkUwQeSSuI0lZacBCPLLuk5mYa7lnO+VV8HsngscQ7CPSft49U3M Mjc3JzhG5+iC08CsdNN1chuR+wmbBhS6V9RQRw5I+gmt1S3y7jDGaVwl3s4uMm40/F30 lXWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=XRftZJDm3ai0VWDqsu19KPwk20u5uhJ9IOYsAPFplGw=; b=PHdIFqtvPl7d47TnGpXXoZ4jPo/GtVnmSerzEpdKEtx9zQnwyCfwwRnnPkq08n5w91 itR76XGvPFHeA92Sz4kjaEvl1z3UXMHfQjWrLeU7j6ktpWnn5CqJW7y8NbRwWryMtxkG DYFsPtdubjfcAbaj10Idleos2Bc4ep8RQr/2JLiFpyFT1WSWA2MxWe9fm9YnUdJjrZW8 z5v9wpniJDJsfWei9w/2xAX4up5QhKR9c87MnVSbbYn/UXc3r/bPSYJYlDtCfbEdlgDY 5c2grb9zZ7i/jEKmIoSOEQkGhxjw7w+aVC/YsM1nHJav/UHxUhLafJ6akZ029zK0eUD7 E2qQ== 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 a91si9181285pld.674.2017.11.10.07.38.39; Fri, 10 Nov 2017 07:38:39 -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 S1753410AbdKJPih (ORCPT + 23 others); Fri, 10 Nov 2017 10:38:37 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:58152 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753146AbdKJPhu (ORCPT ); Fri, 10 Nov 2017 10:37:50 -0500 Received: from wuerfel.lan ([109.193.157.232]) by mrelayeu.kundenserver.de (mreue104 [212.227.15.145]) with ESMTPA (Nemesis) id 0MWjbX-1ekRYk2TTH-00XqFL; Fri, 10 Nov 2017 16:37:33 +0100 From: Arnd Bergmann To: Anil Gurumurthy , Sudarsana Kalluru , "James E . J . Bottomley" , "Martin K . Petersen" Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, y2038@lists.linaro.org, hch@lst.de, hare@suse.com, jthumshirn@suse.de, Arnd Bergmann Subject: [PATCH 6/7] scsi: bfa: try to sanitize vendor netlink events Date: Fri, 10 Nov 2017 16:37:14 +0100 Message-Id: <20171110153715.1929456-7-arnd@arndb.de> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20171110153715.1929456-1-arnd@arndb.de> References: <20171110153715.1929456-1-arnd@arndb.de> X-Provags-ID: V03:K0:F+ZmV3vkh9+pIezdX/G6DQPShDK66QHv4SUZGh4JAhigcmX/WCk beupxNC1blBzU5Dz99JFx9RJW3h7N0R4bmPBFYrFFQvdJoOGRCWJMRwFHJwkYkMLtHStHrk PCzikwUDOqCXutfcOTRU6LKamVHazFJP0xmey5Pe4Pm61HWNVWPAQaUjygVDCBUu+JzSyTP Mp0v0ulletjNSNIGSekuQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:ETXCMT/dZBI=:Em6yaPe1AOD9d0LIXJH9No CWoWle67bsmaMmwHlCI3h0eUfKZyYXC2tLJndCfXZ5huo00Y7zodJ1L1FZTpFHwl06vEU/uMR zp2YiUW3hqUxQXiYQilzBnew6AHkayCEZauI+T9EavOAHeMAFSbbHGqpIaDB5/SwRF261j1NW ah1OL/lcR9tyB+BZiSAYgoJFmoXd9gu45D5qeskBo70rAgAMibjlBpezlabikLCnAApZ0zv7r odcjPzrkfP8Q7M5/LgqhrjLQKcDKoxRmE6XRZ3SG938/QunORZ6jF5p+2hqEZkk0ncjabJUAN ZjMNa/7XKo24uVNookG3ZqAMMnVzaMtix4SyTiysERSi2D9ko4gQr3tl6riTNip2BlVn2Q4wC 2nMPlqUx/aLXgV3vOEsqgQSypJABnXIUEaZExb16kgg0LJ+fE6Xsg/pXW+7fbsY7LfaGGvvwZ KnhuaIGo6qGvrU4Dpq9XZEo8K7Yu3oGexW8292VJnqr7wvedBwfaLxuDN3fJ9baSsD3XB9viL 7FxUOvaLbXk9DqFAUhvT8PkadVQqy3WioT42kMSn9uW7Qd0wDX0/sS40Uvw3sKATrK0FiVAdr vvM1frrWCiJFQGgNl/ZxQW2DHt8Ryjs7/4SFjIPsI4JXi6HheKr5ZQuqAEkZF5o6kD8SkzCv/ 4V0eniGq6a3w8MAlKKa4v1czsnUqrbykiZ1iyVpkLJYKhfQBoLK6ugrUKJ8wz/ZpJvOhgALTL j6o1nC/7s5c4bVJ1vcAJ/Y3ehXbpLkeuHW+giA== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org bfa_aen_entry_s is passed to user space in a netlink message, but is defined using a 'struct timeval' and an 'enum' that are not only different between architectures, but also between 32-bit user space and 64-bit kernels they may run on, as well as depending on the particular C library that defines timeval. This changes the in-kernel definition to no longer use the timeval type directly but instead use two open-coded 'unsigned long' members. This keeps the existing ABI, but making the variable unsigned also helps make it work after y2038, until it overflows in 2106. Since the macro becomes overly complex at this point, I'm changing it to an inline function for readability. I'm not changing the 32-bit user-space ABI at this point, to keep the changes separate, I deally this would be defined using the same binary layout for all architectures. Signed-off-by: Arnd Bergmann --- drivers/scsi/bfa/bfa_defs_svc.h | 3 ++- drivers/scsi/bfa/bfad_im.h | 32 ++++++++++++++++++++++---------- 2 files changed, 24 insertions(+), 11 deletions(-) -- 2.9.0 diff --git a/drivers/scsi/bfa/bfa_defs_svc.h b/drivers/scsi/bfa/bfa_defs_svc.h index e81707f938cb..df1e874015c4 100644 --- a/drivers/scsi/bfa/bfa_defs_svc.h +++ b/drivers/scsi/bfa/bfa_defs_svc.h @@ -1455,7 +1455,8 @@ struct bfa_aen_entry_s { enum bfa_aen_category aen_category; u32 aen_type; union bfa_aen_data_u aen_data; - struct timeval aen_tv; + unsigned long aen_tv_sec; + unsigned long aen_tv_usec; u32 seq_num; u32 bfad_num; }; diff --git a/drivers/scsi/bfa/bfad_im.h b/drivers/scsi/bfa/bfad_im.h index c81ec2a77ef5..7f7616c52814 100644 --- a/drivers/scsi/bfa/bfad_im.h +++ b/drivers/scsi/bfa/bfad_im.h @@ -131,16 +131,28 @@ struct bfad_im_s { } while (0) /* post fc_host vendor event */ -#define bfad_im_post_vendor_event(_entry, _drv, _cnt, _cat, _evt) do { \ - do_gettimeofday(&(_entry)->aen_tv); \ - (_entry)->bfad_num = (_drv)->inst_no; \ - (_entry)->seq_num = (_cnt); \ - (_entry)->aen_category = (_cat); \ - (_entry)->aen_type = (_evt); \ - if ((_drv)->bfad_flags & BFAD_FC4_PROBE_DONE) \ - queue_work((_drv)->im->drv_workq, \ - &(_drv)->im->aen_im_notify_work); \ -} while (0) +static inline void bfad_im_post_vendor_event(struct bfa_aen_entry_s *entry, + struct bfad_s *drv, int cnt, + enum bfa_aen_category cat, + enum bfa_ioc_aen_event evt) +{ + struct timespec64 ts; + + ktime_get_real_ts64(&ts); + /* + * 'unsigned long aen_tv_sec' overflows in y2106 on 32-bit + * architectures, or in 2038 if user space interprets it + * as 'signed'. + */ + entry->aen_tv_sec = ts.tv_sec; + entry->aen_tv_usec = ts.tv_nsec / NSEC_PER_USEC; + entry->bfad_num = drv->inst_no; + entry->seq_num = cnt; + entry->aen_category = cat; + entry->aen_type = evt; + if (drv->bfad_flags & BFAD_FC4_PROBE_DONE) + queue_work(drv->im->drv_workq, &drv->im->aen_im_notify_work); +} struct Scsi_Host *bfad_scsi_host_alloc(struct bfad_im_port_s *im_port, struct bfad_s *);