From patchwork Fri Jan 5 19:30:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10147009 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 5003260153 for ; Fri, 5 Jan 2018 19:30:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 313B0287C7 for ; Fri, 5 Jan 2018 19:30:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2590828911; Fri, 5 Jan 2018 19:30: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 72197287DE for ; Fri, 5 Jan 2018 19:30:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752177AbeAETaH (ORCPT ); Fri, 5 Jan 2018 14:30:07 -0500 Received: from mail-it0-f68.google.com ([209.85.214.68]:36907 "EHLO mail-it0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752121AbeAETaG (ORCPT ); Fri, 5 Jan 2018 14:30:06 -0500 Received: by mail-it0-f68.google.com with SMTP id d137so2815381itc.2 for ; Fri, 05 Jan 2018 11:30:06 -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; bh=LXniF7qK3cnOtUtjuJONqJAwGnlHWbwp5o5nsvVCADM=; b=oCQ5mjab6zNQzLmALkRMxcS9EGdMJvxfXiKayLqRnT/v0Tape629PvZOAiZCT/Mfpt kGvZIky0etUs5cEModHyPkczSKIig1VVJ8uTuR8dooIogFa6T7TxqjIV18J0IIr0tDsm vKkxdUJFZhv2QSDYsxT/ISilce2FaM2STcsNCQXv5zbUyBjvwszPXxq+xCrFiG5WMjgR MqCJKgj8dE9Z632JkPbD8vn1cCKsFthjhOcI6+V/eagtysOrsw6shzoMxoZkpri/iRlK UgOqYzG0Nhhq4vjPji2wnxzhiDAyn5sxhFGHAkcRBDtaeHVHeo4soT1oB8+1zOywt6jz H11g== 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; bh=LXniF7qK3cnOtUtjuJONqJAwGnlHWbwp5o5nsvVCADM=; b=sDu5FppDe6FXm/6jwU9esfOI+gjUKsQha+Ckrdy7yEfTOAtpTUj6vuVOWs+YXOhQ+B IpXM/WiaCdLeYYLSYkqhfVZyqAfPMFTD8d8DsydQpf3DwS/SRDCf9twlexpjFUs75eC7 D5gUmNFapujtVCktJ0CrEg50t1ENWXCx+s6fjJRJvmi+pMXJpwBgpuqmGX66FkQVDx8C p0QDtvFTQZw2U5fp4G8c9V3esNFd4Uuc4fD5K8lqMMzlr8JFcFuk6z4LlTuV1vgEgXFo a6xZrybdvMF9vNhy98RfgX1JT15V8vvlkCehjyrzxHh0OLBt94iep6okK1CcHfAOZ9O4 7LVw== X-Gm-Message-State: AKGB3mKC+iXDcnjxe7aFZwCue8ofmJLucpLc9d232nSShy+KR8H3Px7G CmWVDsld6nzpH401/RrxJTI= X-Google-Smtp-Source: ACJfBovIwzxuOm7OJYrTxlZguRjNxVOv24BecKTRoZ56Xh5JBFNOElyTDbgUMpfoDHQwYAsdh0AYqA== X-Received: by 10.36.250.202 with SMTP id v193mr4379613ith.114.1515180606022; Fri, 05 Jan 2018 11:30:06 -0800 (PST) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.66.175.88]) by smtp.gmail.com with ESMTPSA id y64sm3066238ioy.25.2018.01.05.11.30.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 Jan 2018 11:30:05 -0800 (PST) From: Eric Biggers To: linux-mtd@lists.infradead.org, Richard Weinberger Cc: Artem Bityutskiy , Adrian Hunter , linux-fscrypt@vger.kernel.org, Eric Biggers Subject: [PATCH v2] ubifs: free the encrypted symlink target Date: Fri, 5 Jan 2018 11:30:03 -0800 Message-Id: <20180105193003.118283-1-ebiggers3@gmail.com> X-Mailer: git-send-email 2.16.0.rc0.223.g4a4ac83678-goog 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 ubifs_symlink() forgot to free the kmalloc()'ed buffer holding the encrypted symlink target, creating a memory leak. Fix it. (UBIFS could actually encrypt directly into ui->data, removing the temporary buffer, but that is left for the patch that switches to use the symlink helper functions.) Fixes: ca7f85be8d6c ("ubifs: Add support for encrypted symlinks") Cc: # v4.10+ Signed-off-by: Eric Biggers --- No changes since v1, just resent as standalone patch. fs/ubifs/dir.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index 417fe0b29f23..ef820f803176 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -1216,10 +1216,8 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry, ostr.len = disk_link.len; err = fscrypt_fname_usr_to_disk(inode, &istr, &ostr); - if (err) { - kfree(sd); + if (err) goto out_inode; - } sd->len = cpu_to_le16(ostr.len); disk_link.name = (char *)sd; @@ -1251,11 +1249,10 @@ static int ubifs_symlink(struct inode *dir, struct dentry *dentry, goto out_cancel; mutex_unlock(&dir_ui->ui_mutex); - ubifs_release_budget(c, &req); insert_inode_hash(inode); d_instantiate(dentry, inode); - fscrypt_free_filename(&nm); - return 0; + err = 0; + goto out_fname; out_cancel: dir->i_size -= sz_change; @@ -1268,6 +1265,7 @@ 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; }