Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2234209pxb; Mon, 18 Jan 2021 11:51:24 -0800 (PST) X-Google-Smtp-Source: ABdhPJxFvwwQZq+ixr2rKzNqDefmBq9oLGDn90vUwC9R5DDZsVM8XOS9B5qNR7uoMY0zuTJsbE9z X-Received: by 2002:a50:d90a:: with SMTP id t10mr852216edj.162.1610999484212; Mon, 18 Jan 2021 11:51:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610999484; cv=none; d=google.com; s=arc-20160816; b=BKfl3EB6VQ/T8seSQh7c7XoRuAtpo+Tox8MNHfBrwLtP2kSb0dmT+mZ+iwwtXjcSoQ 6f2/6TOTIlOVU7tkIRbu3sCmZOMxOsJzCfqSUFjf1v/nxo7ccrTw2xptJTrJwFK3isYa X95ruy83Jfsr0FSxqn2OY50xf6z50JFrWG2uT/VEj549Q19I4ntBuGQoCKTYJsqGZRoz 1k/41um0kUzi8OvUVuXj+YlLjLyrTfviAI1vls9AuGJtyfXXPOaU9nA3A+YDvOXow8pu VIgAcQeSypOAmJlF3VR3NENEPDAac5zgZ+l2B/Da1rmDcosm8j8JFe7zNXk+YDAay+Qd GXjQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=F3cXmjxvqsjLDgr4m1O+IrhTdwMu3oOD7hCp15RNbpA=; b=QZuB5JA3j1VSzPywI7XZ4OiC6luJLv+OUkHxXUx9KPCpry8GfonzW9Ofu0DfNk2mS6 M2pZE6dK5WfqO9gQ49zFpWV8H2hIw5cvq+ixlEYxc5kBrDOce3NnQ/s8XUUH+fGmx1dO oiteqzerZ1bHAycuMKrcYzMItY/bUdHUge+wbzBaQC6sUXDiZ2Fi6CrbkIGR+VwUmjUc wkMev5bsVaYcq3kn9w9OECTnOpVtNb/5ftn00PRf12RtClWz/mI1sb21dYoi5Hwv3an2 2z9RCMrylYFXnZr/EW8SJUsvlhTpQUR8cpXmoOqO4RKD38fcLwZ0QGqtIGrlzKN3R7as cNeA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=UzNf2PLp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=android.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gb26si6730738ejc.384.2021.01.18.11.51.00; Mon, 18 Jan 2021 11:51:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@android.com header.s=20161025 header.b=UzNf2PLp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=android.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2437282AbhARTrk (ORCPT + 99 others); Mon, 18 Jan 2021 14:47:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394000AbhART3e (ORCPT ); Mon, 18 Jan 2021 14:29:34 -0500 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C146C0613CF for ; Mon, 18 Jan 2021 11:28:54 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id 6so10253711wri.3 for ; Mon, 18 Jan 2021 11:28:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F3cXmjxvqsjLDgr4m1O+IrhTdwMu3oOD7hCp15RNbpA=; b=UzNf2PLp1S2U0I3mhT/p/5J5doy7rziC9QDRw51E/gGeZvOKBtRpI+ZQ85an52tWj4 Qxs943aizDkTxoNUam73NKwLWKfJdtDNg4K/yHJWvlpAtnzvk5wzJZFobSUn6EDl9Gnw XhmkSzsQb0zA7UWU84z9yC7kdVxTf4t/SK8adNol9+/coqq6mEic+TlGt2fEzW5I+HMw bmFPxFErtcSQ0M6gixkXlvuRZLaPP67dHn42N/NUTlhf+oeIkKP27MQTwnWXBgzWeOiK b3ioT89Ix2V5CmfRaIj1P3g/3WfBZZbAatJbz7cgeDlJ+LaEe9w2FjTiTuf6xw+0UmfG LW3A== 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:mime-version:content-transfer-encoding; bh=F3cXmjxvqsjLDgr4m1O+IrhTdwMu3oOD7hCp15RNbpA=; b=JRO3XFWZLxU35dVtWBG+o3ed6V1lBOWknRA7BMJDC1I/FiJIH8qzwzdEa7dZkCPT7E BEzbrpGEoTLyaOX9qzgLJfuQgFeoNfF2RnAYUCvPQH8MTUlbKksnepRLgPn990Ot1pyn EaXjI5YgSQjB2oEvuWvzAk5VWEFWajObQ/gjQa0yWbT4A1XO3r1ZeakMgrpM5XyXbvc7 YPHKmFwehZHfjchY6zpsKOePPIDVGm4jZNhKcoFVXDXusi/fE+ji/EFK8o6iZCkZkdCV OT96UoayrlwoLuMoQPxCKuev8plWnkxXfwWGEQGXDxmbuFrOcEcU0Ln8wINE7jtIdIPQ rVRw== X-Gm-Message-State: AOAM533kGCLQqxSrLImuc+Nb3MLYb9QTa5IHfYqCk6IOWclt7ib74W6/ DQklZ7faIZh9cWoCNk/AZlj+ug== X-Received: by 2002:adf:c387:: with SMTP id p7mr932317wrf.95.1610998132851; Mon, 18 Jan 2021 11:28:52 -0800 (PST) Received: from balsini.lon.corp.google.com ([2a00:79e0:d:210:41d4:8c90:d38:455d]) by smtp.gmail.com with ESMTPSA id h5sm33583299wrp.56.2021.01.18.11.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Jan 2021 11:28:52 -0800 (PST) From: Alessio Balsini To: Miklos Szeredi Cc: Akilesh Kailash , Amir Goldstein , Antonio SJ Musumeci , David Anderson , Giuseppe Scrivano , Jann Horn , Jens Axboe , Martijn Coenen , Palmer Dabbelt , Paul Lawrence , Peng Tao , Stefano Duo , Zimuzo Ezeozue , wuyan , fuse-devel@lists.sourceforge.net, kernel-team@android.com, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND V11 2/7] fuse: 32-bit user space ioctl compat for fuse device Date: Mon, 18 Jan 2021 19:27:43 +0000 Message-Id: <20210118192748.584213-3-balsini@android.com> X-Mailer: git-send-email 2.30.0.284.gd98b1dd5eaa7-goog In-Reply-To: <20210118192748.584213-1-balsini@android.com> References: <20210118192748.584213-1-balsini@android.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With a 64-bit kernel build the FUSE device cannot handle ioctl requests coming from 32-bit user space. This is due to the ioctl command translation that generates different command identifiers that thus cannot be used for comparisons previous proper manipulation. Explicitly extract type and number from the ioctl command to enable 32-bit user space compatibility on 64-bit kernel builds. Signed-off-by: Alessio Balsini --- fs/fuse/dev.c | 29 ++++++++++++++++++----------- include/uapi/linux/fuse.h | 3 ++- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c index 588f8d1240aa..ff9f3b83f879 100644 --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -2233,37 +2233,44 @@ static int fuse_device_clone(struct fuse_conn *fc, struct file *new) static long fuse_dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - int err = -ENOTTY; + int res; + int oldfd; + struct fuse_dev *fud = NULL; - if (cmd == FUSE_DEV_IOC_CLONE) { - int oldfd; + if (_IOC_TYPE(cmd) != FUSE_DEV_IOC_MAGIC) + return -EINVAL; - err = -EFAULT; - if (!get_user(oldfd, (__u32 __user *) arg)) { + switch (_IOC_NR(cmd)) { + case _IOC_NR(FUSE_DEV_IOC_CLONE): + res = -EFAULT; + if (!get_user(oldfd, (__u32 __user *)arg)) { struct file *old = fget(oldfd); - err = -EINVAL; + res = -EINVAL; if (old) { - struct fuse_dev *fud = NULL; - /* * Check against file->f_op because CUSE * uses the same ioctl handler. */ if (old->f_op == file->f_op && - old->f_cred->user_ns == file->f_cred->user_ns) + old->f_cred->user_ns == + file->f_cred->user_ns) fud = fuse_get_dev(old); if (fud) { mutex_lock(&fuse_mutex); - err = fuse_device_clone(fud->fc, file); + res = fuse_device_clone(fud->fc, file); mutex_unlock(&fuse_mutex); } fput(old); } } + break; + default: + res = -ENOTTY; + break; } - return err; + return res; } const struct file_operations fuse_dev_operations = { diff --git a/include/uapi/linux/fuse.h b/include/uapi/linux/fuse.h index 98ca64d1beb6..54442612c48b 100644 --- a/include/uapi/linux/fuse.h +++ b/include/uapi/linux/fuse.h @@ -903,7 +903,8 @@ struct fuse_notify_retrieve_in { }; /* Device ioctls: */ -#define FUSE_DEV_IOC_CLONE _IOR(229, 0, uint32_t) +#define FUSE_DEV_IOC_MAGIC 229 +#define FUSE_DEV_IOC_CLONE _IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t) struct fuse_lseek_in { uint64_t fh; -- 2.30.0.284.gd98b1dd5eaa7-goog