From patchwork Tue Dec 8 09:38:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chirantan Ekbote X-Patchwork-Id: 11958177 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CC367C433FE for ; Tue, 8 Dec 2020 09:39:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 875C223A82 for ; Tue, 8 Dec 2020 09:39:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727896AbgLHJjX (ORCPT ); Tue, 8 Dec 2020 04:39:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727831AbgLHJjX (ORCPT ); Tue, 8 Dec 2020 04:39:23 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 155C5C06179C for ; Tue, 8 Dec 2020 01:38:37 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id d2so9506403pfq.5 for ; Tue, 08 Dec 2020 01:38:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=MZzXHu8124CoPiJwaurWwTo/J3aWzxR8zutkn5kYXE4=; b=cLSjKMY+5M/Wxu+yh2O7NZxyglmEDWM0aLwhQiTeEexH/lgiEwIrvRPR04rgfIgg57 qob3Y5TLlSVeYmwaleNTLmRYOkmpYranm/yr3xNC4QCz2LD5w/LdS7Sz2LWQJLZLhLlL agxWngKVcRmg/0NgXFpV0OzfrKBvsDiCpdc3M= 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=MZzXHu8124CoPiJwaurWwTo/J3aWzxR8zutkn5kYXE4=; b=SGt9KoFvYG+xDHyN8a3560e/ONwJc7NQ60xLNPLPFshqQIMi5AW/vlrb3dLgBMrSvR Le0tm8zm0mbxxDqlfCrlmfNVRpNXjgu0e393xFYSC0NgGP6k+p82CldiI3/EPiaUv+lh 4mWRrUoo+2J3XzU7W14Ktq5GDPn9hkZ6xdscRSrp6iCqzxCPQvxdGhqqzoItfwyYIzEP bQE9brUxFVVO8IqfHG/28HhC4eLjyBTfet59GxZP49py49dHPnUNA9xz/ustw6yIweTi 8I9o282tab6QiP4NYZ11qiYikfUhMItatXf4Kf7iBIifmcaHs/kCi+yB/SubkYdVl6Bd XxhA== X-Gm-Message-State: AOAM530Q3HGi5m4iPbrUYbZOOZvKb8bO1PvSHt++2/wDFMu6NJB9UdiW PMeNqxPNHcPWYSMwDahzvdqdUg== X-Google-Smtp-Source: ABdhPJwBR9nzBYoQZVpt5jYIr1+9fnAlay9LUen4gZ5/oJDzx7ZaWriMZuKnoe0Oj9m7nE81FdrvTg== X-Received: by 2002:a63:5466:: with SMTP id e38mr21888757pgm.242.1607420316694; Tue, 08 Dec 2020 01:38:36 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:f693:9fff:fef4:2537]) by smtp.gmail.com with ESMTPSA id c3sm15175754pgm.41.2020.12.08.01.38.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Dec 2020 01:38:36 -0800 (PST) From: Chirantan Ekbote To: Miklos Szeredi Cc: linux-fsdevel@vger.kernel.org, Dylan Reid , Suleiman Souhlal , fuse-devel@lists.sourceforge.net, Eric Biggers , linux-fscrypt@vger.kernel.org, Chirantan Ekbote Subject: [PATCH v2 1/2] fuse: Move ioctl length calculation to a separate function Date: Tue, 8 Dec 2020 18:38:07 +0900 Message-Id: <20201208093808.1572227-2-chirantan@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog In-Reply-To: <20201208093808.1572227-1-chirantan@chromium.org> References: <20201207040303.906100-1-chirantan@chromium.org> <20201208093808.1572227-1-chirantan@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org This will make it more readable when we add support for more ioctls. Signed-off-by: Chirantan Ekbote Reviewed-by: Eric Biggers --- fs/fuse/file.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index c03034e8c1529..69cffb77a0b25 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -2703,6 +2703,20 @@ static int fuse_copy_ioctl_iovec(struct fuse_conn *fc, struct iovec *dst, return 0; } +static int fuse_get_ioctl_len(unsigned int cmd, unsigned long arg, size_t *len) +{ + switch (cmd) { + case FS_IOC_GETFLAGS: + case FS_IOC_SETFLAGS: + *len = sizeof(int); + break; + default: + *len = _IOC_SIZE(cmd); + break; + } + + return 0; +} /* * For ioctls, there is no generic way to determine how much memory @@ -2802,16 +2816,9 @@ long fuse_do_ioctl(struct file *file, unsigned int cmd, unsigned long arg, struct iovec *iov = iov_page; iov->iov_base = (void __user *)arg; - - switch (cmd) { - case FS_IOC_GETFLAGS: - case FS_IOC_SETFLAGS: - iov->iov_len = sizeof(int); - break; - default: - iov->iov_len = _IOC_SIZE(cmd); - break; - } + err = fuse_get_ioctl_len(cmd, arg, &iov->iov_len); + if (err) + goto out; if (_IOC_DIR(cmd) & _IOC_WRITE) { in_iov = iov; From patchwork Tue Dec 8 09:38:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chirantan Ekbote X-Patchwork-Id: 11958179 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DD39C1B0D9 for ; Tue, 8 Dec 2020 09:39:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5D0723A84 for ; Tue, 8 Dec 2020 09:39:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727940AbgLHJjZ (ORCPT ); Tue, 8 Dec 2020 04:39:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727958AbgLHJjY (ORCPT ); Tue, 8 Dec 2020 04:39:24 -0500 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03A2EC0617B0 for ; Tue, 8 Dec 2020 01:38:43 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id m9so11705198pgb.4 for ; Tue, 08 Dec 2020 01:38:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u6Ih/DaQwjNwmpSGKSjPdUX3bQk29I1ylU1kAlfOWJQ=; b=UNiwpB5+Mg3wrWFKD/yovjbAcNSxKXCG6U6AeezVcMl6TEJmz/wPWF7zOLeQQkxM2B M0FIkMtsngyJJ+OOgJT1pITrlEGUX9I9XXhoP9MhkgaCeWWliuKAfSs1C0F7KYSVvhWd T+tl+yqQR7+FiqLAHOJuDQsO3ejdJ+OkoOPNI= 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=u6Ih/DaQwjNwmpSGKSjPdUX3bQk29I1ylU1kAlfOWJQ=; b=RrvCpcns4Vrft2FDwPgY1o6ZU8g4tjdSB33a/fSTlGqmNIhY8TURo7km3reV1r8q9K 0XI6IiVz+uYCCIAjtbQ1igEYB+zMiolPNWSEFeG96J+TsfCjnVRlOAcOwsu3fWmJGcyC E9Ma065dV+avGb+ATEeN/WBzFKWdlkQeCdpXe0sVzZWmhSObkexYLpjOpvzwf7laKjLC PFvGYEA2hnclPBn1wdDGhF4aJcvPY8yzkc9q44mwL9Fk7HhG37ouF8nCXT834xdoBfUb XMQSG5u5l1bb6tVYLKFbJsig9/FyOUWtGs1YAvz6XbtmireZ+0DWFMecSS5Dz0xOxvCb 7E6A== X-Gm-Message-State: AOAM533az1dz7vPvojSNqPEIY/kVxC8ajGP4kUKcBn4rjNR/dmGPjEOX 8uEX1oAHMYPBQRpllgzTz0pglA== X-Google-Smtp-Source: ABdhPJzN6ACj7t0UbiR649h/V65nRGCL7gVgf8Gu+qpYSpoAnyKO0rqDWMCrSRBTdQb83UOGy3G14g== X-Received: by 2002:a17:90a:4f03:: with SMTP id p3mr3561418pjh.69.1607420322687; Tue, 08 Dec 2020 01:38:42 -0800 (PST) Received: from localhost ([2401:fa00:8f:203:f693:9fff:fef4:2537]) by smtp.gmail.com with ESMTPSA id s5sm2445374pju.9.2020.12.08.01.38.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 08 Dec 2020 01:38:42 -0800 (PST) From: Chirantan Ekbote To: Miklos Szeredi Cc: linux-fsdevel@vger.kernel.org, Dylan Reid , Suleiman Souhlal , fuse-devel@lists.sourceforge.net, Eric Biggers , linux-fscrypt@vger.kernel.org, Chirantan Ekbote Subject: [PATCH v2 2/2] fuse: Support FS_IOC_GET_ENCRYPTION_POLICY_EX Date: Tue, 8 Dec 2020 18:38:08 +0900 Message-Id: <20201208093808.1572227-3-chirantan@chromium.org> X-Mailer: git-send-email 2.29.2.576.ga3fc446d84-goog In-Reply-To: <20201208093808.1572227-1-chirantan@chromium.org> References: <20201207040303.906100-1-chirantan@chromium.org> <20201208093808.1572227-1-chirantan@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org Chrome OS would like to support this ioctl when passed through the fuse driver. However since it is dynamically sized, we can't rely on the length encoded in the command. Instead check the `policy_size` field of the user provided parameter to get the max length of the data returned by the server. Signed-off-by: Chirantan Ekbote Reviewed-by: Eric Biggers --- fs/fuse/file.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fs/fuse/file.c b/fs/fuse/file.c index 69cffb77a0b25..b64ff7f2fe4dd 100644 --- a/fs/fuse/file.c +++ b/fs/fuse/file.c @@ -19,6 +19,7 @@ #include #include #include +#include static struct page **fuse_pages_alloc(unsigned int npages, gfp_t flags, struct fuse_page_desc **desc) @@ -2710,6 +2711,21 @@ static int fuse_get_ioctl_len(unsigned int cmd, unsigned long arg, size_t *len) case FS_IOC_SETFLAGS: *len = sizeof(int); break; + case FS_IOC_GET_ENCRYPTION_POLICY_EX: { + __u64 policy_size; + struct fscrypt_get_policy_ex_arg __user *uarg = + (struct fscrypt_get_policy_ex_arg __user *)arg; + + if (copy_from_user(&policy_size, &uarg->policy_size, + sizeof(policy_size))) + return -EFAULT; + + if (policy_size > SIZE_MAX - sizeof(policy_size)) + return -EINVAL; + + *len = sizeof(policy_size) + policy_size; + break; + } default: *len = _IOC_SIZE(cmd); break;