Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6687860ybl; Wed, 15 Jan 2020 08:36:59 -0800 (PST) X-Google-Smtp-Source: APXvYqx4NNeY8ta5FA7FjXIgjFjkUW8f3ejVLQlGhr4QHf+fuLuU2FOsb6g1apDiwqInjtytFwLf X-Received: by 2002:aca:36c1:: with SMTP id d184mr540053oia.70.1579106218989; Wed, 15 Jan 2020 08:36:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579106218; cv=none; d=google.com; s=arc-20160816; b=nmX9Z5VGoFFSzkySha7vf/Nt1BrxDHUr7dfanY6AeiEfxwAl5aSJjwa94w7K0BXNv6 v4RZJcNYOK6Qe1EciMybzO1whSbfiCjLLGZPyq+Ax3GtQ8pMH6yzE6bNF2cYpWjfyiUy KiJkyChAPDqlO/XpMwwr0REqV2yE64AUX1muexgRmazSqtw6nY4/xktI5PvurE7pcYDU gfK+B5ShZF/OzWxyH/tRjBssZv4paJNMyEwjoLgGkAIu5w3cCQLs1dtNEYypawSD9vss brt+FKzvSUdl2mGL2Jt605UK8UALA3fD/OnoPERRlFeB8D8OGFGKWJ+l8GBAAlz1UIte mxUA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=olwgOJsEeGbNBTUIn8I937CVc6Quj9K/XMlhmcyLdhM=; b=O7DLnC03U4F5XQUYmLiiXY9quXVEolTMe5EMWqSaGgRTgGa+jGV4+cUs1dEmQoy3zr /i+KxYs4FX1N6hSyokHC9rSvL6iwNzuGe1cSVxP3ayRm9fop26HPn6xkkXStelWS7yex 68Ig07cJYOiZxvQxNXCLTyseMknJ7opcUP7jGgvQU9miJ9uITPXVShwIaK8bIgG0Bc5x FX75qBzFpkBOSiUiNeJAczsE3enVjFa6zAAvxLxvVSf3Y/lBzqXNehFImXH0+1uAldqd AyP2eqyg7UPc6752eHkZpQlNsBXmWtN81TYnAKDumwSjkHKaSUKYNyPXS+iyBobDqQRV pObw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dHKN/fBF"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c24si11475656otf.14.2020.01.15.08.36.45; Wed, 15 Jan 2020 08:36:58 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b="dHKN/fBF"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728946AbgAOQfu (ORCPT + 99 others); Wed, 15 Jan 2020 11:35:50 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:47050 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726574AbgAOQfu (ORCPT ); Wed, 15 Jan 2020 11:35:50 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579106149; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type; bh=olwgOJsEeGbNBTUIn8I937CVc6Quj9K/XMlhmcyLdhM=; b=dHKN/fBFGIqkjz1Xj1KF4jmk8qJ+DQ2gRt49umOT5W0fi/95Fzr7lKUVUP2b1EW6QOn/ho 2Zge1S4YtMDG8A3PGmO/roEIO1ebP2b76LP9be6jKrKXcwBoIVrsfRlX2qEyNrgSKHcPA4 geDKJbrVNNbRpIe8FmiaHaaIRmhcvJQ= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-64-0sHrwlvyPHS8usrKZHIRnA-1; Wed, 15 Jan 2020 11:35:46 -0500 X-MC-Unique: 0sHrwlvyPHS8usrKZHIRnA-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5E12A800A02; Wed, 15 Jan 2020 16:35:44 +0000 (UTC) Received: from asgard.redhat.com (ovpn-112-36.ams2.redhat.com [10.36.112.36]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2116D60CD3; Wed, 15 Jan 2020 16:35:40 +0000 (UTC) Date: Wed, 15 Jan 2020 17:35:38 +0100 From: Eugene Syromiatnikov To: linux-fsdevel@vger.kernel.org, io-uring@vger.kernel.org, Alexander Viro , Jens Axboe Cc: linux-kernel@vger.kernel.org, Jeff Moyer , "Dmitry V. Levin" Subject: [PATCH] io_uring: fix compat for IORING_REGISTER_FILES_UPDATE Message-ID: <20200115163538.GA13732@asgard.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org fds field of struct io_uring_files_update is problematic with regards to compat user space, as pointer size is different in 32-bit, 32-on-64-bit, and 64-bit user space. In order to avoid custom handling of compat in the syscall implementation, make fds __u64 and use u64_to_user_ptr in order to retrieve it. Also, align the field naturally and check that no garbage is passed there. Fixes: c3a31e605620c279 ("io_uring: add support for IORING_REGISTER_FILES_UPDATE") Signed-off-by: Eugene Syromiatnikov --- fs/io_uring.c | 4 +++- include/uapi/linux/io_uring.h | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 38b5405..677ef90 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -4445,13 +4445,15 @@ static int io_sqe_files_update(struct io_ring_ctx *ctx, void __user *arg, return -EINVAL; if (copy_from_user(&up, arg, sizeof(up))) return -EFAULT; + if (up.resv) + return -EINVAL; if (check_add_overflow(up.offset, nr_args, &done)) return -EOVERFLOW; if (done > ctx->nr_user_files) return -EINVAL; done = 0; - fds = (__s32 __user *) up.fds; + fds = u64_to_user_ptr(up.fds); while (nr_args) { struct fixed_file_table *table; unsigned index; diff --git a/include/uapi/linux/io_uring.h b/include/uapi/linux/io_uring.h index a3300e1..55cfcb7 100644 --- a/include/uapi/linux/io_uring.h +++ b/include/uapi/linux/io_uring.h @@ -178,7 +178,8 @@ struct io_uring_params { struct io_uring_files_update { __u32 offset; - __s32 *fds; + __u32 resv; + __aligned_u64 /* __s32 * */ fds; }; #endif -- 2.1.4