From patchwork Fri Dec 13 20:52:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 181584 Delivered-To: patch@linaro.org Received: by 2002:a92:3001:0:0:0:0:0 with SMTP id x1csp1143285ile; Fri, 13 Dec 2019 12:53:06 -0800 (PST) X-Google-Smtp-Source: APXvYqxIprQEwPHErKYye/Z+u2XJrEpMEWhK0YMWouU7sm2PRBPM8xPP96DtZCYzQipj2ZX4B8dc X-Received: by 2002:a05:6830:1459:: with SMTP id w25mr15882291otp.270.1576270386785; Fri, 13 Dec 2019 12:53:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576270386; cv=none; d=google.com; s=arc-20160816; b=WHijEXBgNJ8c5wKPT9MEl8DzOzZNugJQ/G+qoAtsYqIQnVdc9Hs9bBD1tTFs4PCu54 eNvDlPJqUhD3+lkdRp3LTL7F1vwpwQ8JPIU50YgIBHaVDcRZE/hEyG5Yl5kSeWX02SVn HPUliy3UHXrPpsOI30mkYCLwPfHxKDsk4rDSxPA/gOB/+CXz5UgWoTo6IMZQemdx6tqy LS7jN8ev2uRFrBYvseOE0QMPTJDbYACRL1So2B7DlHV3n3DE7Niwa0iHjrCcgQGhBmTK QeCENYeNNb+ZMQA2JPw9k8DsUspNJtRAqLcb/flRZ+/+yETZoHTusrnzq38vDYEr+Nia hfsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=ur6ghsqsHfbHTMC2isb5Ktvb7FbvTyv0GhCsohnn8pA=; b=mlNrV/v1GX2//WKai5xnVApWD+ah/4b6I/9j4UmZmJ23k1EoCKkXYwi3oEl1qQvioi ncOAe7VeugPasNwm63WR01P25QvPpsTO9FuLYekYzBbkPf16VKfJeQ5N+2H94KA1h9ld bv5wH8KPUOOueauDER5blocVQYwwdqq/GaphXWkkmvOJarGQLOV/08KP7yrPDXKXwJ4s IcUZweg2LMGNmQFiIJuFUSkHveJ2WqdmEBJWkaLP3iATjctu5r7Q67/h+6PJV8xW1Q3V SIcIZNMsymEORUaMZ8aiBnkRw4fsj0QInUvZCztzdhIWSVJahyh49MrL539Y2r4AHxBA wRCg== 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 i8si5796797otp.254.2019.12.13.12.53.06; Fri, 13 Dec 2019 12:53:06 -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 S1726678AbfLMUxF (ORCPT + 27 others); Fri, 13 Dec 2019 15:53:05 -0500 Received: from mout.kundenserver.de ([212.227.126.135]:45503 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725747AbfLMUxE (ORCPT ); Fri, 13 Dec 2019 15:53:04 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue012 [212.227.15.129]) with ESMTPA (Nemesis) id 1MSqbe-1iI6wz0KPG-00UKf7; Fri, 13 Dec 2019 21:52:47 +0100 From: Arnd Bergmann To: y2038@lists.linaro.org, linux-kernel@vger.kernel.org, Jeff Dike , Richard Weinberger , Anton Ivanov Cc: Arnd Bergmann , Alex Dewar , Jens Axboe , linux-um@lists.infradead.org Subject: [PATCH v2 05/24] um: ubd: use 64-bit time_t where possible Date: Fri, 13 Dec 2019 21:52:10 +0100 Message-Id: <20191213205221.3787308-2-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191213204936.3643476-1-arnd@arndb.de> References: <20191213204936.3643476-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:mLyO11lzsTki85ngmdRuvZQpffJE2UOI4zLl+uc1b6gL7mCwrB9 c4BgVt5uCUzPtnrvPR47NFtCTQDbqK683AKz1oOVgkq1Ekn5QNnTb1ut06woz/k2ZQC0VGj oK9OwugHAi5tHUSZe5Suajf52pVQAEIFogivdYkNfobGxUDXRSqRAqJMt6v1s4DxoODHhav NLcxeYqWv0+1bUYscHkYw== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1; V03:K0:lpUtqwLVCdA=:kSwfzyihbAiqRgvELZEZgw ofiAbMScdf0/jQ3hSJSbhdbyxxp+89hmduPl29UJkD3j5yjZIA2oA3utstDuUPtm30kcNJ2NI AEpPoyKYgCNnf97kHPdp1Uf/8oQaNKSuL2GSU7i1kanybJcWX92AmB7WnD8qEDsFhNMa+qvNh 34zxoGTz9YXc71+JnkFdEzavB8jJ71oGjZQEyIqmVJul7tkc2xaHpvdaYzvZJtqizzuYywi9b pmARFGfViQU2mhSrJBpKFBrCKLb0wWNmF0m5aRNkRDJwVd/3z0KNMOf0BI1jwHOgRzSEdQVco ADciMXWq4KfrjGF0EEwGeCtpqnzNQDgvUFTcPeCidp9+0adoL4ix/8b93qp9QHTvWWAhA4/FA 6JvEn8s91+CGmsJHeiaYENY0Jv8agE7mfyl3oBL5Mb58IBlisMXxcuC+9rg4n5p748+CJeOGz qTtkI6v8tx4SYiqCYJj8XUaj8ngKL+61rXJ179AupfW54rlYDICkwor5FIlIPNlAkuLI08Zyi hH3QuzvF6ZnbyifOy8xqY7TowWpvLvkO9Kf0VpmcUQiaSqBfasmMKGqZx/aqTRu8wPdqfGtxp jdhCKQzx1dqD+Y2etSM1KPr1abmF+GoPrusLcbicfouDBPZ/ixNoXiz1OgyI/+YcTVoTSk9za 0Az7W/wQ5bG+RSNvuyrwEEmmxrnCMXsC0gQ1MKUz7BonL1WklSo8HDdkDymkbhnNY/hsSij1f AmTRuwuSKiFQreqJXHEUlB8/vhXxvRMQd1j0oU3MZWbX8iTx/wFv4KtanhxyeN15RwYaoon6c qBciYRn8Rg9RNO8tUTbLHNCvyJhk+73r5JopIHEvYsY5Pk8ZyaEeVloh7InU3IvkdRVd3deDg cjYxvXEdMto71IAA8WdQ== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ubd code suffers from a possible y2038 overflow on 32-bit architectures, both for the cow header and the os_file_modtime() function. Replace time_t with time64_t to extend the ubd_kern side as much as possible. Whether this makes a difference for the user side depends on the host libc implementation that may use either 32-bit or 64-bit time_t. For the cow file format, the header contains an unsigned 32-bit timestamp, which is good until y2106, passing this through a 'long long' gives us a consistent interpretation between 32-bit and 64-bit um kernels. Signed-off-by: Arnd Bergmann --- arch/um/drivers/cow.h | 2 +- arch/um/drivers/cow_user.c | 7 ++++--- arch/um/drivers/ubd_kern.c | 10 +++++----- arch/um/include/shared/os.h | 2 +- arch/um/os-Linux/file.c | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) -- 2.20.0 diff --git a/arch/um/drivers/cow.h b/arch/um/drivers/cow.h index 760c507dd5b6..103adac691ed 100644 --- a/arch/um/drivers/cow.h +++ b/arch/um/drivers/cow.h @@ -11,7 +11,7 @@ extern int init_cow_file(int fd, char *cow_file, char *backing_file, extern int file_reader(__u64 offset, char *buf, int len, void *arg); extern int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg, __u32 *version_out, - char **backing_file_out, time_t *mtime_out, + char **backing_file_out, long long *mtime_out, unsigned long long *size_out, int *sectorsize_out, __u32 *align_out, int *bitmap_offset_out); diff --git a/arch/um/drivers/cow_user.c b/arch/um/drivers/cow_user.c index 74b0c2686c95..29b46581ddd1 100644 --- a/arch/um/drivers/cow_user.c +++ b/arch/um/drivers/cow_user.c @@ -17,6 +17,7 @@ #define PATH_LEN_V1 256 +/* unsigned time_t works until year 2106 */ typedef __u32 time32_t; struct cow_header_v1 { @@ -197,7 +198,7 @@ int write_cow_header(char *cow_file, int fd, char *backing_file, int sectorsize, int alignment, unsigned long long *size) { struct cow_header_v3 *header; - unsigned long modtime; + long long modtime; int err; err = cow_seek_file(fd, 0); @@ -276,7 +277,7 @@ int file_reader(__u64 offset, char *buf, int len, void *arg) int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg, __u32 *version_out, char **backing_file_out, - time_t *mtime_out, unsigned long long *size_out, + long long *mtime_out, unsigned long long *size_out, int *sectorsize_out, __u32 *align_out, int *bitmap_offset_out) { @@ -363,7 +364,7 @@ int read_cow_header(int (*reader)(__u64, char *, int, void *), void *arg, /* * this was used until Dec2005 - 64bits are needed to represent - * 2038+. I.e. we can safely do this truncating cast. + * 2106+. I.e. we can safely do this truncating cast. * * Additionally, we must use be32toh() instead of be64toh(), since * the program used to use the former (tested - I got mtime diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index 6627d7c30f37..dcabb463e011 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -561,7 +561,7 @@ static inline int ubd_file_size(struct ubd *ubd_dev, __u64 *size_out) __u32 version; __u32 align; char *backing_file; - time_t mtime; + time64_t mtime; unsigned long long size; int sector_size; int bitmap_offset; @@ -600,9 +600,9 @@ static int read_cow_bitmap(int fd, void *buf, int offset, int len) return 0; } -static int backing_file_mismatch(char *file, __u64 size, time_t mtime) +static int backing_file_mismatch(char *file, __u64 size, time64_t mtime) { - unsigned long modtime; + time64_t modtime; unsigned long long actual; int err; @@ -628,7 +628,7 @@ static int backing_file_mismatch(char *file, __u64 size, time_t mtime) return -EINVAL; } if (modtime != mtime) { - printk(KERN_ERR "mtime mismatch (%ld vs %ld) of COW header vs " + printk(KERN_ERR "mtime mismatch (%lld vs %lld) of COW header vs " "backing file\n", mtime, modtime); return -EINVAL; } @@ -671,7 +671,7 @@ static int open_ubd_file(char *file, struct openflags *openflags, int shared, unsigned long *bitmap_len_out, int *data_offset_out, int *create_cow_out) { - time_t mtime; + time64_t mtime; unsigned long long size; __u32 version, align; char *backing_file; diff --git a/arch/um/include/shared/os.h b/arch/um/include/shared/os.h index 506bcd1bca68..0f30204b6afa 100644 --- a/arch/um/include/shared/os.h +++ b/arch/um/include/shared/os.h @@ -150,7 +150,7 @@ extern int os_sync_file(int fd); extern int os_file_size(const char *file, unsigned long long *size_out); extern int os_pread_file(int fd, void *buf, int len, unsigned long long offset); extern int os_pwrite_file(int fd, const void *buf, int count, unsigned long long offset); -extern int os_file_modtime(const char *file, unsigned long *modtime); +extern int os_file_modtime(const char *file, long long *modtime); extern int os_pipe(int *fd, int stream, int close_on_exec); extern int os_set_fd_async(int fd); extern int os_clear_fd_async(int fd); diff --git a/arch/um/os-Linux/file.c b/arch/um/os-Linux/file.c index 5133e3afb96f..fbda10535dab 100644 --- a/arch/um/os-Linux/file.c +++ b/arch/um/os-Linux/file.c @@ -341,7 +341,7 @@ int os_file_size(const char *file, unsigned long long *size_out) return 0; } -int os_file_modtime(const char *file, unsigned long *modtime) +int os_file_modtime(const char *file, long long *modtime) { struct uml_stat buf; int err;