From patchwork Fri Dec 15 17:42:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10115701 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C95D46019C for ; Fri, 15 Dec 2017 17:47:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B729429EE1 for ; Fri, 15 Dec 2017 17:47:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC0C62A024; Fri, 15 Dec 2017 17:47:03 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 4F44829EE1 for ; Fri, 15 Dec 2017 17:47:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755663AbdLORrD (ORCPT ); Fri, 15 Dec 2017 12:47:03 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:46652 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755977AbdLORqy (ORCPT ); Fri, 15 Dec 2017 12:46:54 -0500 Received: by mail-pg0-f68.google.com with SMTP id b11so6242023pgu.13; Fri, 15 Dec 2017 09:46:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7h9u2IkSjgruzrqPm2ZdvIPY0oq8UnAIjc03Bq1yGA8=; b=W0Fnso+qPwb19DhcFeVivfWFcYJJw3aUXifa43FvHJy86+bgjEBALYXN3WaOPEiTwH WPtw3tdogqdoKylvjIegZ94tkLkKO711zm1O5XJD9XmJzJzI2UV5ZKZ+8JYlLCoDc2xb wsMWsA9qMhk3+cDwp+V7AzVbZlfR1igatNeZBa8SZTcossYI16XXJH4D4f9yotYYo+hr URZ4HI+8Shoe+LndMHe5m0KQekV3d8bsLfbq8qkEa/ENePIBoQJ+NOmUWxyZ2dWZH7LT KJd32Xs8tBgBaRTkGSyZ2CmIkhBqd2n5eMb64Bo/cE6p/EO6N5XvcjyBwNuicF7g+1mr jMvA== 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=7h9u2IkSjgruzrqPm2ZdvIPY0oq8UnAIjc03Bq1yGA8=; b=S3AlC8+9WmMfmT9b4Cs2mreYkzb+poFvVkWGXwjzPbrKUBbA5vkrXxjkQNDH+UXUWz 341chJcqERC/YG87sPrCv635hrDh3nA0LxrAkqs5cLksfIChXK737rKdJcrjpvXj7axe sWmW5370k6wtUVsNeB5youyOLNOzEy72EWE0v3zJjQ9AZShIAntD+xIBGWkw81My9KbZ Z7tEsJ7znPe39hLMD3eMY3TslNWZm2XIfgW2uJs7lynmg9d1xkHliGTfMzMTogYNG1lL vscdqXmDOevl6cQI6vkMOhMu898AMafSpQjCYTLzdqpTTIy917tVXVXh2XXNcKAdnoOa FmMg== X-Gm-Message-State: AKGB3mL/9towgqISB/e9858Aem/nt8x9psu+sun21HfCQvw4fpQzzDYF J5gLFmm3LVwHKpy77cGqRF+bfwyFS1U= X-Google-Smtp-Source: ACJfBova1Ogukjzzv5IfFwmLgdIBEC38RFwNIi1/py15p/DC0I1P8fjhA3fV65/sxXYxmLZQW4r9eg== X-Received: by 10.101.70.70 with SMTP id k6mr12477057pgr.292.1513360013221; Fri, 15 Dec 2017 09:46:53 -0800 (PST) Received: from zzz.localdomain (c-67-185-97-198.hsd1.wa.comcast.net. [67.185.97.198]) by smtp.gmail.com with ESMTPSA id j62sm12980149pfc.18.2017.12.15.09.46.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Dec 2017 09:46:52 -0800 (PST) From: Eric Biggers To: linux-fscrypt@vger.kernel.org Cc: "Theodore Y . Ts'o" , Jaegeuk Kim , linux-ext4@vger.kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-mtd@lists.infradead.org, Eric Biggers Subject: [PATCH 14/24] f2fs: switch to fscrypt ->symlink() helper functions Date: Fri, 15 Dec 2017 09:42:15 -0800 Message-Id: <20171215174225.31583-15-ebiggers3@gmail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171215174225.31583-1-ebiggers3@gmail.com> References: <20171215174225.31583-1-ebiggers3@gmail.com> Sender: linux-fscrypt-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fscrypt@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers Signed-off-by: Eric Biggers --- fs/f2fs/namei.c | 66 ++++++++++++++------------------------------------------- 1 file changed, 16 insertions(+), 50 deletions(-) diff --git a/fs/f2fs/namei.c b/fs/f2fs/namei.c index 28bdf8828e73..5b114844806c 100644 --- a/fs/f2fs/namei.c +++ b/fs/f2fs/namei.c @@ -496,27 +496,16 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, struct f2fs_sb_info *sbi = F2FS_I_SB(dir); struct inode *inode; size_t len = strlen(symname); - struct fscrypt_str disk_link = FSTR_INIT((char *)symname, len + 1); - struct fscrypt_symlink_data *sd = NULL; + struct fscrypt_str disk_link; int err; if (unlikely(f2fs_cp_error(sbi))) return -EIO; - if (f2fs_encrypted_inode(dir)) { - err = fscrypt_get_encryption_info(dir); - if (err) - return err; - - if (!fscrypt_has_encryption_key(dir)) - return -ENOKEY; - - disk_link.len = (fscrypt_fname_encrypted_size(dir, len) + - sizeof(struct fscrypt_symlink_data)); - } - - if (disk_link.len > dir->i_sb->s_blocksize) - return -ENAMETOOLONG; + err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize, + &disk_link); + if (err) + return err; err = dquot_initialize(dir); if (err) @@ -526,7 +515,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, if (IS_ERR(inode)) return PTR_ERR(inode); - if (f2fs_encrypted_inode(inode)) + if (IS_ENCRYPTED(inode)) inode->i_op = &f2fs_encrypted_symlink_inode_operations; else inode->i_op = &f2fs_symlink_inode_operations; @@ -536,38 +525,13 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, f2fs_lock_op(sbi); err = f2fs_add_link(dentry, inode); if (err) - goto out; + goto out_handle_failed_inode; f2fs_unlock_op(sbi); alloc_nid_done(sbi, inode->i_ino); - if (f2fs_encrypted_inode(inode)) { - struct qstr istr = QSTR_INIT(symname, len); - struct fscrypt_str ostr; - - sd = kzalloc(disk_link.len, GFP_NOFS); - if (!sd) { - err = -ENOMEM; - goto err_out; - } - - err = fscrypt_get_encryption_info(inode); - if (err) - goto err_out; - - if (!fscrypt_has_encryption_key(inode)) { - err = -ENOKEY; - goto err_out; - } - - ostr.name = sd->encrypted_path; - ostr.len = disk_link.len; - err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr); - if (err) - goto err_out; - - sd->len = cpu_to_le16(ostr.len); - disk_link.name = (char *)sd; - } + err = fscrypt_encrypt_symlink(inode, symname, len, &disk_link); + if (err) + goto err_out; err = page_symlink(inode, disk_link.name, disk_link.len); @@ -594,12 +558,14 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, f2fs_unlink(dir, dentry); } - kfree(sd); - f2fs_balance_fs(sbi, true); - return err; -out: + goto out_free_encrypted_link; + +out_handle_failed_inode: handle_failed_inode(inode); +out_free_encrypted_link: + if (disk_link.name != (unsigned char *)symname) + kfree(disk_link.name); return err; }