From patchwork Fri Dec 15 17:42:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10115707 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 396CD6019C for ; Fri, 15 Dec 2017 17:47:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 271D629EE1 for ; Fri, 15 Dec 2017 17:47:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C0AC2A024; Fri, 15 Dec 2017 17:47:10 +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 B4B6329EE1 for ; Fri, 15 Dec 2017 17:47:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756164AbdLORrI (ORCPT ); Fri, 15 Dec 2017 12:47:08 -0500 Received: from mail-pf0-f194.google.com ([209.85.192.194]:40679 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755976AbdLORq5 (ORCPT ); Fri, 15 Dec 2017 12:46:57 -0500 Received: by mail-pf0-f194.google.com with SMTP id v26so6632691pfl.7; Fri, 15 Dec 2017 09:46:57 -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=NuTbkKe4elZo2puZHwGjcXBzqPEzWheIkZrtToyJ/ks=; b=S/kfEotfQ9unlWAqpbWcItaSIiw9nakeBszf888hyIUWzxuY9ENJT72XTH20oOPWmm glY5dbpsUs3MKA18r9FDKmrCR7jEzFxAvmaSyn3FaMHYaNoun7sdN76hZzRkYQaNDwiV xnEzXMvEaoUDAf0LHt0Nb1dLb0/oPAq4yOV1JN2QPEjQnIwyssHFfv/MT1EboZohVK1g EBPcNXT43+kuN+IMQn2C0QrN89OzcCiPSDdWGFAw8+GyVX4iNfcE3o/2968cYVdVDFHP GKi2Paw9unHQDN0YBGdppIGJcHeqnmC9gBKStCqFSnhdTi0eFRM/PT9SJYMWcLiNRt+M Xpeg== 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=NuTbkKe4elZo2puZHwGjcXBzqPEzWheIkZrtToyJ/ks=; b=lgCkV0vb8iRYL4f+BMXxchTlwYN9dP6UzVDs3QlWeghw6YKdS0j8/T9oW+mGPD006h xn/rfbTQMPxfCZm9q2jTgcPi92W4RaliP5Rz0CJskDfr51noCpnn8XfCPiJzO8bRknHV P3Wq2QBcqU80lUvxIJ362mhH6j+Js+pSKK2YVLO3mCfDSfvYTS1KfRo07G0gJayBuFij yQ1UHWi19Vx3LQmtenp4KKcTW3x0gbBIelPQK9qVBBW16fWB1X4fUOLVJVaUSABbiTgM Y4Smbl1pw7p189v2SnILv0YcZF3e8AVxN2Y6gOY1oFvl6nAM4LWZW9bY4gr6jRNMO5k7 H3Bw== X-Gm-Message-State: AKGB3mJVIhSttdlqhVDowdCzOZcJ1kzqFWboTB0NI2QG65WCjIas2fTe h3XO7fz31LtmY32eVoQnG2ygwiBxWlk= X-Google-Smtp-Source: ACJfBovPGsQ+EmVqhdepOJRoj+WdrGr5KBlwSegbu1/5IZ2BzGgXJn2/r/03zeDIA4H6csUABD3Vwg== X-Received: by 10.159.255.5 with SMTP id bi5mr14396627plb.30.1513360016775; Fri, 15 Dec 2017 09:46:56 -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.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Dec 2017 09:46:55 -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 17/24] ubifs: switch to fscrypt ->symlink() helper functions Date: Fri, 15 Dec 2017 09:42:18 -0800 Message-Id: <20171215174225.31583-18-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/ubifs/dir.c | 55 ++++++++++++------------------------------------------- 1 file changed, 12 insertions(+), 43 deletions(-) diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index ef820f803176..518c10255881 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -1149,38 +1149,24 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry, struct ubifs_info *c = dir->i_sb->s_fs_info; int err, len = strlen(symname); int sz_change = CALC_DENT_SIZE(len); - struct fscrypt_str disk_link = FSTR_INIT((char *)symname, len + 1); - struct fscrypt_symlink_data *sd = NULL; + struct fscrypt_str disk_link; struct ubifs_budget_req req = { .new_ino = 1, .new_dent = 1, .new_ino_d = ALIGN(len, 8), .dirtied_ino = 1 }; struct fscrypt_name nm; - if (ubifs_crypt_is_encrypted(dir)) { - err = fscrypt_get_encryption_info(dir); - if (err) - goto out_budg; - - if (!fscrypt_has_encryption_key(dir)) { - err = -EPERM; - goto out_budg; - } + dbg_gen("dent '%pd', target '%s' in dir ino %lu", dentry, + symname, dir->i_ino); - disk_link.len = (fscrypt_fname_encrypted_size(dir, len) + - sizeof(struct fscrypt_symlink_data)); - } + err = fscrypt_prepare_symlink(dir, symname, len, UBIFS_MAX_INO_DATA, + &disk_link); + if (err) + return err; /* * Budget request settings: new inode, new direntry and changing parent * directory inode. */ - - dbg_gen("dent '%pd', target '%s' in dir ino %lu", dentry, - symname, dir->i_ino); - - if (disk_link.len > UBIFS_MAX_INO_DATA) - return -ENAMETOOLONG; - err = ubifs_budget_space(c, &req); if (err) return err; @@ -1202,36 +1188,20 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry, goto out_inode; } - if (ubifs_crypt_is_encrypted(dir)) { - struct qstr istr = QSTR_INIT(symname, len); - struct fscrypt_str ostr; - - sd = kzalloc(disk_link.len, GFP_NOFS); - if (!sd) { - err = -ENOMEM; - goto out_inode; - } - - ostr.name = sd->encrypted_path; - ostr.len = disk_link.len; - - err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr); + if (IS_ENCRYPTED(inode)) { + disk_link.name = ui->data; /* encrypt directly into ui->data */ + err = fscrypt_encrypt_symlink(inode, symname, len, &disk_link); if (err) goto out_inode; - - sd->len = cpu_to_le16(ostr.len); - disk_link.name = (char *)sd; } else { + memcpy(ui->data, disk_link.name, disk_link.len); inode->i_link = ui->data; } - memcpy(ui->data, disk_link.name, disk_link.len); - ((char *)ui->data)[disk_link.len - 1] = '\0'; - /* * The terminating zero byte is not written to the flash media and it * is put just to make later in-memory string processing simpler. Thus, - * data length is @len, not @len + %1. + * data length is @disk_link.len - 1, not @disk_link.len. */ ui->data_len = disk_link.len - 1; inode->i_size = ubifs_inode(inode)->ui_size = disk_link.len - 1; @@ -1265,7 +1235,6 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry, fscrypt_free_filename(&nm); out_budg: ubifs_release_budget(c, &req); - kfree(sd); return err; }