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: 849336 X-Patchwork-Delegate: richard@nod.at Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="cKCVUotr"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=infradead.org header.i=@infradead.org header.b="Af1kPNqh"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="S/kfEotf"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yyysB0vFpz9t34 for ; Sat, 16 Dec 2017 05:00:45 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=E3UJ4v9ju8+hzCDjGhYqua4eDF3MT+HiJsKafMafZVM=; b=cKCVUotr00exZq7LJ2dqTaGjcC VRRY0Wr7IhDUOLJRzbT7Ggcp8u3zS2KlTxO4+zSYI2lcwEBb8GylYEsnICrCqRGjvQ1xfOZgnak6Z cM0k3NQn1e01jeUJQ3i1XOO5o0ZXQ9jbazJpHaEnBJ25/EbaA1iLoFVMihg2pCduqtuxN3mLFl6zY a/eMRBeqVFA6OUs9ElZoUb/Nml0fNWTo3xowdYRId1Ljm00TGk0t6CNIA5GpijSM840RnKl2lSXPV fioHDbrMI8SozhKt6rAsmFa2B+cx3wYMpcb68VQHbRjiidwVf9Zj3CQSDewNJFvWyJSp6JRY5YhGu eoXVWCzw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ePuHR-0003wF-9U; Fri, 15 Dec 2017 18:00:17 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ePu4w-0000Ar-HW for linux-mtd@bombadil.infradead.org; Fri, 15 Dec 2017 17:47:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=NuTbkKe4elZo2puZHwGjcXBzqPEzWheIkZrtToyJ/ks=; b=Af1kPNqhfrd8w1R0bFwsXjJHt AehJTqL4didGN9lW/CEKbChBufL55hcAD9gdAnubhDghurcV2/vrdk2bPLTHFZYxVw9dhTqHDlqkz kU2WJICduj1VjjM1ugJ9nR0ZDt771r8e4LLn76UHfZUCzuTVcErM8yZIt+T4StLg+zgdGkYfMtNMT VomGuRYbekYniNEqnU8wwr+DkO0cp3iFlIFjXPU8pZFPPY4nvbs12w0ZNgC+POAsE5PRZnvfJGEwL nAf7c+GxAlxREytVzGNHMi2IyVktj+rIxduhq/0MthV9rxzR4GR3RdlOI4ChaIbsDSpCy1h/jWAFS A2cuOWOtQ==; Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ePu4q-0004lZ-49 for linux-mtd@lists.infradead.org; Fri, 15 Dec 2017 17:47:17 +0000 Received: by mail-pf0-x242.google.com with SMTP id m26so6623712pfj.11 for ; Fri, 15 Dec 2017 09:46:58 -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=oX9DmqvFDQF4XPW1NJ1UyMTkrNG8B3/w6CQV9EYiX4duRWyxMmxCLiymP2XlTqLsPK a29w6Du0JMOlPbocE9uUT+/l80lBTezOGA8mEcYt2LWdFTG64x8to8LOr2Yi1Yg5qFpw uO59WevpPwIfGVIDULKdZr5eY+uygCMNowiHNo0FaBB/Nc6DqVmuxSnflIAjT0+38/CA XCAv5llo+4viMEzO2hrtBWuGrQ0E03cCwP8LJxGddt0Ludmca0bkxRp4yBED0VG45vwv kb+NtDnSQP9++a0KANx7Kjgc8kuKWqOGfcWcMAN4mMeQZRky312BYiMuG1RLkbRHiRy9 l1uQ== X-Gm-Message-State: AKGB3mKTtUqRZnRly1z1L4jbfk4UxMPEWkqUXvk3MF2dMEKhPEgvwNvO OvQz2TlyENn2WeuyxsLSWRY= 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171215_174716_330678_28D0038E X-CRM114-Status: GOOD ( 14.57 ) X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.4.1 on casper.infradead.org summary: Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:400e:c00:0:0:0:242 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (ebiggers3[at]gmail.com) 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (ebiggers3[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Theodore Y . Ts'o" , Eric Biggers , linux-f2fs-devel@lists.sourceforge.net, linux-mtd@lists.infradead.org, Jaegeuk Kim , linux-ext4@vger.kernel.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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; }