From patchwork Fri Dec 15 17:42:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10115697 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 E18FD6019C for ; Fri, 15 Dec 2017 17:47:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF10129EE1 for ; Fri, 15 Dec 2017 17:47:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C3FB52A024; Fri, 15 Dec 2017 17:47:00 +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 63C8C29EE1 for ; Fri, 15 Dec 2017 17:47:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756114AbdLORq7 (ORCPT ); Fri, 15 Dec 2017 12:46:59 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:43115 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755684AbdLORqv (ORCPT ); Fri, 15 Dec 2017 12:46:51 -0500 Received: by mail-pf0-f194.google.com with SMTP id e3so6624926pfi.10; Fri, 15 Dec 2017 09:46:51 -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=0IR7UT2zvvL0I+26VAcmsJ/6F3RTt3Vrnywg+uir/WI=; b=MNg7eGN78xGXI9L7LTZSuZrnEp8VJLTxSs1KDWf4vhrhI1KLcsqo9uS0seqPa1hOas OCuNy9GMwJukissnaO4xZ0Dq2Je4ha4TzzJ10ZZs5UIiSF87FVMALvhN4fuD9Zf2LZDr 7FcNA1NFO9HWJ5B+wjfKgPK1oDtAOuaYcNyUtg+i/eyLtneHuHH6Q9aPg0NkSp9fUafW HCWoXw7ouf25AUq4+iRWdc0rLQIvkx4aTuGJepKmZal1BWUbCEsj+GPe/KLQjHi96cmm eIEoTpa5dQ4ehmKraDvUMV+7mT6LA6Ydm4K0Vq5aoHKKj9DyTJ0SKGtrPD41XRuBTUCP oCpg== 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=0IR7UT2zvvL0I+26VAcmsJ/6F3RTt3Vrnywg+uir/WI=; b=l2ktv/K/eRgal0JtkWzQksRAM95zLAbALUq1J9cWg/avMsJc5Bnhgk9zgxWZ9hVdo7 Wow9nd8UGH/SWOcbzEZF9wmLRuaCrnTX7Y12hs0wjZDOvrKPLCAJi6F/UUYIfGr+qVIi rQxu/yPR+dbYMsG9VQlNo0t401fCP4371lOkdPUyy3VtNEQVwuNAEa0cn9XqnS5GgU42 sUBOtgOyV5gjiP0mcCqXquM3LkmOqKoSWtbav5n+lexYk20CIKDub95Y+jLzcnVjts/M PYWr3T9jUC++wnvW6YCn4HR0fDr00OL5Vlrcah1q/BDK5cMdOWXYFTg3FZyheC/ogI9N iPOQ== X-Gm-Message-State: AKGB3mJVp1VLUThs6dreWmRvGROEPYsmA0gsGjCsB/P6bdeaC6TEQjBk WhUa8D2GzdwAUvid8JSDjsUjE2xiIwA= X-Google-Smtp-Source: ACJfBouSn16a09zYxylbykdUDnifD2e/JhWc6YSgX78HL2ZskrN5SqbGG9MietRCkV5tuWRKzzuXyw== X-Received: by 10.84.195.36 with SMTP id i33mr13819098pld.27.1513360011042; Fri, 15 Dec 2017 09:46:51 -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.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Dec 2017 09:46:50 -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 12/24] ext4: switch to fscrypt ->symlink() helper functions Date: Fri, 15 Dec 2017 09:42:13 -0800 Message-Id: <20171215174225.31583-13-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/ext4/namei.c | 58 +++++++++++++++------------------------------------------ 1 file changed, 15 insertions(+), 43 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 798b3ac680db..e291bb90a233 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -3052,39 +3052,19 @@ static int ext4_symlink(struct inode *dir, struct inode *inode; int err, len = strlen(symname); int credits; - bool encryption_required; struct fscrypt_str disk_link; - struct fscrypt_symlink_data *sd = NULL; if (unlikely(ext4_forced_shutdown(EXT4_SB(dir->i_sb)))) return -EIO; - disk_link.len = len + 1; - disk_link.name = (char *) symname; - - encryption_required = (ext4_encrypted_inode(dir) || - DUMMY_ENCRYPTION_ENABLED(EXT4_SB(dir->i_sb))); - if (encryption_required) { - 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)); - sd = kzalloc(disk_link.len, GFP_KERNEL); - if (!sd) - return -ENOMEM; - } - - if (disk_link.len > dir->i_sb->s_blocksize) { - err = -ENAMETOOLONG; - goto err_free_sd; - } + err = fscrypt_prepare_symlink(dir, symname, len, dir->i_sb->s_blocksize, + &disk_link); + if (err) + return err; err = dquot_initialize(dir); if (err) - goto err_free_sd; + return err; if ((disk_link.len > EXT4_N_BLOCKS * 4)) { /* @@ -3113,27 +3093,18 @@ static int ext4_symlink(struct inode *dir, if (IS_ERR(inode)) { if (handle) ext4_journal_stop(handle); - err = PTR_ERR(inode); - goto err_free_sd; + return PTR_ERR(inode); } - if (encryption_required) { - struct qstr istr; - struct fscrypt_str ostr = - FSTR_INIT(sd->encrypted_path, disk_link.len); - - istr.name = (const unsigned char *) symname; - istr.len = len; - err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr); + if (IS_ENCRYPTED(inode)) { + err = fscrypt_encrypt_symlink(inode, symname, len, &disk_link); if (err) goto err_drop_inode; - sd->len = cpu_to_le16(ostr.len); - disk_link.name = (char *) sd; inode->i_op = &ext4_encrypted_symlink_inode_operations; } if ((disk_link.len > EXT4_N_BLOCKS * 4)) { - if (!encryption_required) + if (!IS_ENCRYPTED(inode)) inode->i_op = &ext4_symlink_inode_operations; inode_nohighmem(inode); ext4_set_aops(inode); @@ -3175,7 +3146,7 @@ static int ext4_symlink(struct inode *dir, } else { /* clear the extent format for fast symlink */ ext4_clear_inode_flag(inode, EXT4_INODE_EXTENTS); - if (!encryption_required) { + if (!IS_ENCRYPTED(inode)) { inode->i_op = &ext4_fast_symlink_inode_operations; inode->i_link = (char *)&EXT4_I(inode)->i_data; } @@ -3190,16 +3161,17 @@ static int ext4_symlink(struct inode *dir, if (handle) ext4_journal_stop(handle); - kfree(sd); - return err; + goto out_free_encrypted_link; + err_drop_inode: if (handle) ext4_journal_stop(handle); clear_nlink(inode); unlock_new_inode(inode); iput(inode); -err_free_sd: - kfree(sd); +out_free_encrypted_link: + if (disk_link.name != (unsigned char *)symname) + kfree(disk_link.name); return err; }