From patchwork Fri Dec 15 17:42:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 10115715 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 7CE30603FA for ; Fri, 15 Dec 2017 17:47:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B75929F27 for ; Fri, 15 Dec 2017 17:47:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6067C29EE1; Fri, 15 Dec 2017 17:47:17 +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 0865C29F27 for ; Fri, 15 Dec 2017 17:47:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756149AbdLORrF (ORCPT ); Fri, 15 Dec 2017 12:47:05 -0500 Received: from mail-pg0-f66.google.com ([74.125.83.66]:34663 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755927AbdLORq4 (ORCPT ); Fri, 15 Dec 2017 12:46:56 -0500 Received: by mail-pg0-f66.google.com with SMTP id j4so6264164pgp.1; Fri, 15 Dec 2017 09:46:56 -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=aFarVJDJje9P8A6brStU+9Fg/KwsmO+5Nm4yG0QfpvQ=; b=Qnx65BE9fByLvULF64eIvsLom8UqNM/DUIEPiBZjrILvjW7AUnTudNA44d334IWzUY x+7S0Fqd3Lz7iZj9Cmel61RdqMjKOyh1iS2JiO+ADZUKmVC5P1FULD6VSoRv2bzt6sLU EBD/dRIoXlAsUzopnBNUV+9g0tc3+4UOkXYSZxCWwRgNjRDeXwYZtUoxduFtQyVVWMXO YaDAFQtoyAsYvBUqw08PFtl5fFFnwJKVTtwMzcT5rtx4wo3IbnV5nn1Qe8PhO6MY/wD/ 4roj0/ym77qgqm4EbBYqn08YKObJfmscF4Ni3Qx1LAPHQu3sYFZPOQXquGUvJPaStVFl 7fvQ== 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=aFarVJDJje9P8A6brStU+9Fg/KwsmO+5Nm4yG0QfpvQ=; b=g/thh3oxvFKa0g886KdVM6qBmr+wbgAdyefrJW/Z+0JTf8m1TBhBld6Th6hV0Pa/Fu Li94p/vACe52rkq16NZ8YWhL7h8DbXWFyJxOjVxt9r3TX3W+kYv+V62d/FpRUzZB34cH ZhekBmqM4AlnWWg1H4OVAmpcfGpvhbbhmc7sEj8yvYU1KKQ+/qWHCbSBfdg5j7Wjotz5 zvc6AvcO+EuyXXB2RWvQgJUNLAFH2lX9v55o8yO5XIULcBE5F3s/rQdmo8CBvCaR7xcK jgBIru8Mnc891e3EkTe8O1A6voBj63e83Hl9Bx/1End+nC86wSuKRJWyYCkRU5MOwHbO 28Iw== X-Gm-Message-State: AKGB3mK76NNwKF6V7d9dov3TpJpIMPp7QbUjhgxpvxMymLHPAmSYitOM 3B0QlgHB2T4QUGkiVMs+jkRJ+hsNjbA= X-Google-Smtp-Source: ACJfBosskEJuXW1XE433vZGiMyTmm2VATGIrW3cDXhJjDgLU/xmZKbAKNd2Ks1sM8uxBHMDvF7/xPA== X-Received: by 10.159.230.11 with SMTP id u11mr13977330plq.185.1513360015450; Fri, 15 Dec 2017 09:46:55 -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.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Dec 2017 09:46:54 -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 , stable@vger.kernel.org Subject: [PATCH 16/24] ubifs: free the encrypted symlink target Date: Fri, 15 Dec 2017 09:42:17 -0800 Message-Id: <20171215174225.31583-17-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 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 --- 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; }