From patchwork Sat Dec 15 01:22:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Bowler X-Patchwork-Id: 10731947 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8C5C31399 for ; Sat, 15 Dec 2018 01:22:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 392172D02C for ; Sat, 15 Dec 2018 01:22:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2CB3A2D035; Sat, 15 Dec 2018 01:22:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9A5F2D02C for ; Sat, 15 Dec 2018 01:22:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726609AbeLOBWW (ORCPT ); Fri, 14 Dec 2018 20:22:22 -0500 Received: from mail-io1-f68.google.com ([209.85.166.68]:45307 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726448AbeLOBWW (ORCPT ); Fri, 14 Dec 2018 20:22:22 -0500 Received: by mail-io1-f68.google.com with SMTP id n3so5882251iog.12 for ; Fri, 14 Dec 2018 17:22:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=draconx-ca.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=O0jbTnsJVXq/zO/dVO60c7FrR3Hsxcm1aEUIw7I1iT4=; b=mFhenyq1JDRlYXBTHRblFYp+ropV1zg/kUXBH97b0xsWw+esHRFjLkEFVZZve6nLgx MUpaqzztETpDGGWdTiqu1anL9ZlHD5Uc2kxjHcWTJP0iaFqiptZ3SfrYLVDflc21lOLo YM4N3m6yfWaWeeTg4IfWBSrfb5TmGD5ZpRrNF7F7huNkzm/bzk5k3/15pXTvqDyYFymM bwJs0v5geRFtowr3AAfQ/ZjRym/yiJT4O7XeBqWkcPY5V0hYL/Ri55RqZrO0du3lT7x4 5ENK8Ar2t7reo+UoQClczkarAl6j2cTc9RltJWi8rxdcWx/bCDVhrc1yFdxthGqGh9op WXXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=O0jbTnsJVXq/zO/dVO60c7FrR3Hsxcm1aEUIw7I1iT4=; b=REOu8vgUJX93s3dTd/46oWwYIDzS3keFGm4Cumswnr17NFeTiDmKaQaX2PbbN/TMlv Th+IAKkbNtgE1sAnGesOopbKVASEcUh/oLkd9zXsJJkUH1TnvEC0s7bY+frUJK/19uF4 02VjQIlcAwECZikr9iFPgoZJoAhrfRk6jrnlEDNKvv0ZF6un1nPgX7O5pslumlB0ARKM 2EBbrJs1go42B3pcu8dUFxL/MmpJIu9ZoM+V9LRxrR1iLNKPn0DXlkiskyDAgjzLWU9W +xSCw/eD6zDPlxNCI2Z3mfKbQSW8hV8DICps8EZgUMsEvwHH/wZpQeNbKCDzYqnyq0/H Cwfw== X-Gm-Message-State: AA+aEWag72rnvUUprpJfY84UzWwgv5zU84W+EsKtDIe3XZ0g5GihiNQc GVASdMt53fFqziL/WhJpqk1h2+me264+pxaR X-Google-Smtp-Source: AFSGD/WwzmVgYVnuCRk99ymd1rxhXZQMV7kr1+w3rSRfAz/MrA5oXqLrb6K88VqqI4GU3T5guTPc7g== X-Received: by 2002:a5d:93d0:: with SMTP id j16mr4455053ioo.215.1544836940534; Fri, 14 Dec 2018 17:22:20 -0800 (PST) Received: from localhost (ip-24-156-181-89.user.start.ca. [24.156.181.89]) by smtp.gmail.com with ESMTPSA id i15sm2629786ioj.54.2018.12.14.17.22.19 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 14 Dec 2018 17:22:19 -0800 (PST) From: Nick Bowler To: linux-xfs@vger.kernel.org Cc: Brian Foster , Dave Chinner , "Darrick J. Wong" Subject: [RFC PATCH v2 2/3] xfs: Fix bulkstat compat ioctls on x32 userspace. Date: Fri, 14 Dec 2018 20:22:58 -0500 Message-Id: <20181215012259.28358-3-nbowler@draconx.ca> X-Mailer: git-send-email 2.18.1 In-Reply-To: <20181215012259.28358-1-nbowler@draconx.ca> References: <20181215012259.28358-1-nbowler@draconx.ca> Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The bulkstat family of ioctls are problematic on x32, because there is a mixup of native 32-bit and 64-bit conventions. The xfs_fsop_bulkreq struct contains pointers and 32-bit integers so that matches the native 32-bit layout, and that means the ioctl implementation goes into the regular compat path on x32. However, the 'ubuffer' member of that struct in turn refers to either struct xfs_inogrp or xfs_bstat (or an array of these). On x32, those structures match the native 64-bit layout. The compat implementation writes out the 32-bit version of these structures. This is not the expected format for x32 userspace, causing problems. Fortunately the functions which actually output these xfs_inogrp and xfs_bstat structures have an easy way to select which output format is required, so we just need a little tweak to select the right format on x32. Signed-off-by: Nick Bowler Reviewed-by: Darrick J. Wong --- fs/xfs/xfs_ioctl32.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/fs/xfs/xfs_ioctl32.c b/fs/xfs/xfs_ioctl32.c index 4c34efcbf7e8..1cdc75dca779 100644 --- a/fs/xfs/xfs_ioctl32.c +++ b/fs/xfs/xfs_ioctl32.c @@ -241,6 +241,32 @@ xfs_compat_ioc_bulkstat( int done; int error; + /* + * Output structure handling functions. Depending on the command, + * either the xfs_bstat and xfs_inogrp structures are written out + * to userpace memory via bulkreq.ubuffer. Normally the compat + * functions and structure size are the correct ones to use ... + */ + inumbers_fmt_pf inumbers_func = xfs_inumbers_fmt_compat; + bulkstat_one_pf bs_one_func = xfs_bulkstat_one_compat; + size_t bs_one_size = sizeof(compat_xfs_bstat_t); + +#ifdef CONFIG_X86_X32 + if (in_x32_syscall()) { + /* + * ... but on x32 the input xfs_fsop_bulkreq has pointers + * which must be handled in the "compat" (32-bit) way, while + * the xfs_bstat and xfs_inogrp structures follow native 64- + * bit layout convention. So adjust accordingly, otherwise + * the data written out in compat layout will not match what + * x32 userspace expects. + */ + inumbers_func = xfs_inumbers_fmt; + bs_one_func = xfs_bulkstat_one; + bs_one_size = sizeof(xfs_bstat_t); + } +#endif + /* done = 1 if there are more stats to get and if bulkstat */ /* should be called again (unused here, but used in dmapi) */ @@ -272,15 +298,15 @@ xfs_compat_ioc_bulkstat( if (cmd == XFS_IOC_FSINUMBERS_32) { error = xfs_inumbers(mp, &inlast, &count, - bulkreq.ubuffer, xfs_inumbers_fmt_compat); + bulkreq.ubuffer, inumbers_func); } else if (cmd == XFS_IOC_FSBULKSTAT_SINGLE_32) { int res; - error = xfs_bulkstat_one_compat(mp, inlast, bulkreq.ubuffer, - sizeof(compat_xfs_bstat_t), NULL, &res); + error = bs_one_func(mp, inlast, bulkreq.ubuffer, + bs_one_size, NULL, &res); } else if (cmd == XFS_IOC_FSBULKSTAT_32) { error = xfs_bulkstat(mp, &inlast, &count, - xfs_bulkstat_one_compat, sizeof(compat_xfs_bstat_t), + bs_one_func, bs_one_size, bulkreq.ubuffer, &done); } else error = -EINVAL;