From patchwork Wed Dec 18 16:39:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 11301413 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E3F6B138C for ; Wed, 18 Dec 2019 16:40:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CC2FB24672 for ; Wed, 18 Dec 2019 16:40:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727184AbfLRQkR (ORCPT ); Wed, 18 Dec 2019 11:40:17 -0500 Received: from mout.kundenserver.de ([212.227.17.10]:44199 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727124AbfLRQkQ (ORCPT ); Wed, 18 Dec 2019 11:40:16 -0500 Received: from threadripper.lan ([149.172.19.189]) by mrelayeu.kundenserver.de (mreue108 [212.227.15.145]) with ESMTPA (Nemesis) id 1MUGqT-1iGuOr0t6J-00RLZB; Wed, 18 Dec 2019 17:40:06 +0100 From: Arnd Bergmann To: "Darrick J . Wong" , linux-xfs@vger.kernel.org Cc: y2038@lists.linaro.org, Arnd Bergmann , Brian Foster , Dave Chinner , Allison Collins , Jan Kara , Eric Sandeen , linux-kernel@vger.kernel.org Subject: [PATCH 2/3] xfs: disallow broken ioctls without compat-32-bit-time Date: Wed, 18 Dec 2019 17:39:29 +0100 Message-Id: <20191218163954.296726-2-arnd@arndb.de> X-Mailer: git-send-email 2.20.0 In-Reply-To: <20191218163954.296726-1-arnd@arndb.de> References: <20191218163954.296726-1-arnd@arndb.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:6ujAzFNzbSvWONOGFgSWinycKZWnfNnaCJ6HIW30mi/PzDQi6Wu hKOaMDeT4IWEcnmQS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dc2ZK2rYdMc8XF/+EGyHkwb2h8oF EQJjOtppA7S+gjkCJBRg== Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org When building a kernel that disables support for 32-bit time_t system calls, it also makes sense to disable the old xfs_bstat ioctls completely, as they truncate the timestamps to 32-bit values once the extended times are supported. Any application using these needs to be updated to use the v5 interfaces. Signed-off-by: Arnd Bergmann --- fs/xfs/xfs_ioctl.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c index 7b35d62ede9f..d43582e933a0 100644 --- a/fs/xfs/xfs_ioctl.c +++ b/fs/xfs/xfs_ioctl.c @@ -36,6 +36,7 @@ #include "xfs_reflink.h" #include "xfs_ioctl.h" +#include #include #include @@ -617,6 +618,23 @@ xfs_fsinumbers_fmt( return xfs_ibulk_advance(breq, sizeof(struct xfs_inogrp)); } +/* disallow y2038-unsafe ioctls with CONFIG_COMPAT_32BIT_TIME=n */ +static bool xfs_have_compat_bstat_time32(unsigned int cmd) +{ + if (IS_ENABLED(CONFIG_COMPAT_32BIT_TIME)) + return true; + + if (IS_ENABLED(CONFIG_64BIT) && !in_compat_syscall()) + return true; + + if (cmd == XFS_IOC_FSBULKSTAT_SINGLE || + cmd == XFS_IOC_FSBULKSTAT || + cmd == XFS_IOC_SWAPEXT) + return false; + + return true; +} + STATIC int xfs_ioc_fsbulkstat( xfs_mount_t *mp, @@ -637,6 +655,9 @@ xfs_ioc_fsbulkstat( if (!capable(CAP_SYS_ADMIN)) return -EPERM; + if (!xfs_have_compat_bstat_time32(cmd)) + return -EINVAL; + if (XFS_FORCED_SHUTDOWN(mp)) return -EIO; @@ -1815,6 +1836,11 @@ xfs_ioc_swapext( struct fd f, tmp; int error = 0; + if (!xfs_have_compat_bstat_time32(XFS_IOC_SWAPEXT)) { + error = -EINVAL; + goto out; + } + /* Pull information for the target fd */ f = fdget((int)sxp->sx_fdtarget); if (!f.file) {