From patchwork Fri Dec 15 17:42:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10115699 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 E546D6019C for ; Fri, 15 Dec 2017 17:47:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D339529EE1 for ; Fri, 15 Dec 2017 17:47:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C7DC02A024; Fri, 15 Dec 2017 17:47:02 +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 6141629EE1 for ; Fri, 15 Dec 2017 17:47:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756128AbdLORrA (ORCPT ); Fri, 15 Dec 2017 12:47:00 -0500 Received: from mail-pg0-f67.google.com ([74.125.83.67]:32935 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755996AbdLORqx (ORCPT ); Fri, 15 Dec 2017 12:46:53 -0500 Received: by mail-pg0-f67.google.com with SMTP id g7so6264391pgs.0; Fri, 15 Dec 2017 09:46:52 -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=+O7LzCBrntjLKo0EnLfNfm4vMP2Y7fb3f6XdNdYB5SM=; b=AuOFSZrwJ1w1LSfqZJQ8jy32m0I0ca+Qrk4QBevZR4d6W/3TsNFi7bKuLJJB26KDyW zT4ZFJ5ySuENpx/037M30LWfLGZLxr9vT0wVoZjbYHX6g0NF1iPn3zjC3WHRM+m6n3aN e3+g8iDqNMv1VGV4S2HA6S/U+/MqnZ0POINTElGaHZSJpBKf0JdN1cloWJVdgPSdV+aD 7Ku848us/wE6iMaxE4CDi8wie/7THhcZJELTm4Kj6SLBqc/s7T99ZM+GI2uReaYFZ5f+ EdATe5W+rakH5Bt557TeiVQENCqSEuSnI0//DzEw+F26x3xaIjiS2ITApqmvcQC3TK8i BjXw== 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=+O7LzCBrntjLKo0EnLfNfm4vMP2Y7fb3f6XdNdYB5SM=; b=FBm6AhPpkHnl+a2EtRoRl56ld3K01Vm8oDOSwtjmfGTh9vRgXRvcKRq01wMl89v4JQ iFiKkqKPZXsotJqzUNX4x7hg3qtERSbancx+2v9rUlgRdVY/KwSYlNfElIHp93gPfdqP uH4y+1eOqlOZbq7yPz7mHLO6s6e4IQY+Nt++09z8kuAO9NJo54G8Dby+ruwS+gh0QW81 IXehdUcXiufSwAeC8fdKaWaPvZm46/m9GA5Smc4g16GbaavvS/SaUwXX1UHa9LRbnvzC PKM1TMz+kwqmiqOT8q6+sh2Ee6v6hYpGOIAPLYWGIRfPaUCDYQT9f24iz0DLWmC2b9KT MFwA== X-Gm-Message-State: AKGB3mKYdypXAWwix2ipwYEDI//dE/SQh3e+bwgmTQv3EKWZATsXboou V+hZZE7bFkNngVQTLdfITr0HxYMfZgo= X-Google-Smtp-Source: ACJfBos9PqfDy3AJiU7ORxmn8isdEHwvam2zbrU20xHRYU8sbWivRbc1phunFTls2YV+xgRjMHszhg== X-Received: by 10.159.216.141 with SMTP id s13mr14605114plp.310.1513360012164; Fri, 15 Dec 2017 09:46:52 -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.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Dec 2017 09:46:51 -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 13/24] ext4: switch to fscrypt_get_symlink() Date: Fri, 15 Dec 2017 09:42:14 -0800 Message-Id: <20171215174225.31583-14-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/symlink.c | 43 ++++++------------------------------------- 1 file changed, 6 insertions(+), 37 deletions(-) diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c index a2006c9af1d9..dd05af983092 100644 --- a/fs/ext4/symlink.c +++ b/fs/ext4/symlink.c @@ -28,59 +28,28 @@ static const char *ext4_encrypted_get_link(struct dentry *dentry, struct delayed_call *done) { struct page *cpage = NULL; - char *caddr, *paddr = NULL; - struct fscrypt_str cstr, pstr; - struct fscrypt_symlink_data *sd; - int res; - u32 max_size = inode->i_sb->s_blocksize; + const void *caddr; + unsigned int max_size; + const char *paddr; if (!dentry) return ERR_PTR(-ECHILD); - res = fscrypt_get_encryption_info(inode); - if (res) - return ERR_PTR(res); - if (ext4_inode_is_fast_symlink(inode)) { - caddr = (char *) EXT4_I(inode)->i_data; + caddr = EXT4_I(inode)->i_data; max_size = sizeof(EXT4_I(inode)->i_data); } else { cpage = read_mapping_page(inode->i_mapping, 0, NULL); if (IS_ERR(cpage)) return ERR_CAST(cpage); caddr = page_address(cpage); + max_size = inode->i_sb->s_blocksize; } - /* Symlink is encrypted */ - sd = (struct fscrypt_symlink_data *)caddr; - cstr.name = sd->encrypted_path; - cstr.len = le16_to_cpu(sd->len); - if ((cstr.len + sizeof(struct fscrypt_symlink_data) - 1) > max_size) { - /* Symlink data on the disk is corrupted */ - res = -EFSCORRUPTED; - goto errout; - } - - res = fscrypt_fname_alloc_buffer(inode, cstr.len, &pstr); - if (res) - goto errout; - paddr = pstr.name; - - res = fscrypt_fname_disk_to_usr(inode, 0, 0, &cstr, &pstr); - if (res) - goto errout; - - /* Null-terminate the name */ - paddr[pstr.len] = '\0'; + paddr = fscrypt_get_symlink(inode, caddr, max_size, done); if (cpage) put_page(cpage); - set_delayed_call(done, kfree_link, paddr); return paddr; -errout: - if (cpage) - put_page(cpage); - kfree(paddr); - return ERR_PTR(res); } const struct inode_operations ext4_encrypted_symlink_inode_operations = {