Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp628682ybi; Fri, 26 Jul 2019 16:19:50 -0700 (PDT) X-Google-Smtp-Source: APXvYqyQNzBVCMAd7fqH1YqbMrSkorCUXSxshWW90BjUcqmmD5A+ZWqCfByMPFALDalIzPFahOGz X-Received: by 2002:a17:902:7791:: with SMTP id o17mr99986800pll.27.1564183190059; Fri, 26 Jul 2019 16:19:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564183190; cv=none; d=google.com; s=arc-20160816; b=J1ZoPSixP3KhsesjPzpsQwFVte0qSvCXQESV9v3z8x2oHPFLjpmH7AxjLKGX7m+GET Rw9EdYD6aV345RuBRpgvoO339b2u26T+m+ZzxGL9UcUmpG2cnok9cmqOvvaWZbjqph5r BEo9TsphqCC5Q688CkZ0SY/QHvh8Y6QfvbqFAceI8pdWwyH7YWWJc/PdBnLZrpmjR1eP PFtNXPyec9bbz8oFaJgG2eZxDWAhAsraslobhNRo5IaKnfqcxXmcyrCRrhG3eX+mkk6C PJlane7oy2yL+XwcA/ph3lgPCvFykhW3q8HG/MjWeO3D8Ak29JxFReGfBKLRylKl17XZ wwbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5wKAIVLG4XRlUWsgpBLRNZ6hD9p3TnfhBrqxaVhkNF8=; b=F5OgoT0/Qe3amf3Ic78Wo7Q88ddxoFeCZXJjPaC1QDVBvAJSbm5CbAD00NRPOEKdBj loSgdhHhRBChaW7SMOqb16yQkjD8eWl+5G0CJr4EIe5Rtz1R7VeqfvA1do5K80FFkgG+ uUR5fJ4ktIC6LopoYXmqBOkV+WxNy0P7PWtvl0zDW5mtq016rPeiW/LJ4qn2GosVJL7u 4/5ZXxtDhR0w5clNfrvU22bbusJ7ZSogD4QfbWfQOw6ODQTQmE6P/GwMqH8w+sXOlo4r 5iwcbkLL646PXnqaao8UZ2GzuKEZbYROTfByyYgwZrAFFB3DlmTPLvzGb9+96IY7n2iu Luvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="u/+SS+iU"; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j15si7742222pgi.336.2019.07.26.16.19.36; Fri, 26 Jul 2019 16:19:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-crypto-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=@kernel.org header.s=default header.b="u/+SS+iU"; spf=pass (google.com: best guess record for domain of linux-crypto-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387641AbfGZWqG (ORCPT + 99 others); Fri, 26 Jul 2019 18:46:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:52488 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387575AbfGZWqD (ORCPT ); Fri, 26 Jul 2019 18:46:03 -0400 Received: from sol.localdomain (c-24-5-143-220.hsd1.ca.comcast.net [24.5.143.220]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 27CCB22CD4; Fri, 26 Jul 2019 22:46:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564181162; bh=IKiEQFIiMfCYan5GuYDaxi56R4bXsWKFB7+JD7gdczw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u/+SS+iUPkWR2k6QxlCH0itC8t6u6DSzS58eGmA0BgHaoWSLNg19ZJzBz5VL+w9aL vsLWa0EiXbUI5Jk+WvV75k2milvrUZyGHTWIB4jlasqhMJ/VJuMlfjdK5ZxdExiwsK 0ILAcpIb2RSTErjkae7sj2OOZKrBiNk0jKX2V79U= From: Eric Biggers To: linux-fscrypt@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-mtd@lists.infradead.org, linux-api@vger.kernel.org, linux-crypto@vger.kernel.org, keyrings@vger.kernel.org, Paul Crowley , Satya Tangirala Subject: [PATCH v7 14/16] f2fs: wire up new fscrypt ioctls Date: Fri, 26 Jul 2019 15:41:39 -0700 Message-Id: <20190726224141.14044-15-ebiggers@kernel.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190726224141.14044-1-ebiggers@kernel.org> References: <20190726224141.14044-1-ebiggers@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org From: Eric Biggers Wire up the new ioctls for adding and removing fscrypt keys to/from the filesystem, and the new ioctl for retrieving v2 encryption policies. FS_IOC_REMOVE_ENCRYPTION_KEY also required making f2fs_drop_inode() call fscrypt_drop_inode(). For more details see Documentation/filesystems/fscrypt.rst and the fscrypt patches that added the implementation of these ioctls. Signed-off-by: Eric Biggers --- fs/f2fs/file.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ fs/f2fs/super.c | 2 ++ 2 files changed, 48 insertions(+) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index f8d46df8fa9ee..d81dda290b829 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -2184,6 +2184,40 @@ static int f2fs_ioc_get_encryption_pwsalt(struct file *filp, unsigned long arg) return err; } +static int f2fs_ioc_get_encryption_policy_ex(struct file *filp, + unsigned long arg) +{ + if (!f2fs_sb_has_encrypt(F2FS_I_SB(file_inode(filp)))) + return -EOPNOTSUPP; + + return fscrypt_ioctl_get_policy_ex(filp, (void __user *)arg); +} + +static int f2fs_ioc_add_encryption_key(struct file *filp, unsigned long arg) +{ + if (!f2fs_sb_has_encrypt(F2FS_I_SB(file_inode(filp)))) + return -EOPNOTSUPP; + + return fscrypt_ioctl_add_key(filp, (void __user *)arg); +} + +static int f2fs_ioc_remove_encryption_key(struct file *filp, unsigned long arg) +{ + if (!f2fs_sb_has_encrypt(F2FS_I_SB(file_inode(filp)))) + return -EOPNOTSUPP; + + return fscrypt_ioctl_remove_key(filp, (const void __user *)arg); +} + +static int f2fs_ioc_get_encryption_key_status(struct file *filp, + unsigned long arg) +{ + if (!f2fs_sb_has_encrypt(F2FS_I_SB(file_inode(filp)))) + return -EOPNOTSUPP; + + return fscrypt_ioctl_get_key_status(filp, (void __user *)arg); +} + static int f2fs_ioc_gc(struct file *filp, unsigned long arg) { struct inode *inode = file_inode(filp); @@ -3109,6 +3143,14 @@ long f2fs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) return f2fs_ioc_get_encryption_policy(filp, arg); case F2FS_IOC_GET_ENCRYPTION_PWSALT: return f2fs_ioc_get_encryption_pwsalt(filp, arg); + case FS_IOC_GET_ENCRYPTION_POLICY_EX: + return f2fs_ioc_get_encryption_policy_ex(filp, arg); + case FS_IOC_ADD_ENCRYPTION_KEY: + return f2fs_ioc_add_encryption_key(filp, arg); + case FS_IOC_REMOVE_ENCRYPTION_KEY: + return f2fs_ioc_remove_encryption_key(filp, arg); + case FS_IOC_GET_ENCRYPTION_KEY_STATUS: + return f2fs_ioc_get_encryption_key_status(filp, arg); case F2FS_IOC_GARBAGE_COLLECT: return f2fs_ioc_gc(filp, arg); case F2FS_IOC_GARBAGE_COLLECT_RANGE: @@ -3236,6 +3278,10 @@ long f2fs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) case F2FS_IOC_SET_ENCRYPTION_POLICY: case F2FS_IOC_GET_ENCRYPTION_PWSALT: case F2FS_IOC_GET_ENCRYPTION_POLICY: + case FS_IOC_GET_ENCRYPTION_POLICY_EX: + case FS_IOC_ADD_ENCRYPTION_KEY: + case FS_IOC_REMOVE_ENCRYPTION_KEY: + case FS_IOC_GET_ENCRYPTION_KEY_STATUS: case F2FS_IOC_GARBAGE_COLLECT: case F2FS_IOC_GARBAGE_COLLECT_RANGE: case F2FS_IOC_WRITE_CHECKPOINT: diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 6de6cda440315..f5fae8d511a20 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -913,6 +913,8 @@ static int f2fs_drop_inode(struct inode *inode) return 0; } ret = generic_drop_inode(inode); + if (!ret) + ret = fscrypt_drop_inode(inode); trace_f2fs_drop_inode(inode, ret); return ret; } -- 2.22.0