From patchwork Mon Apr 24 17:00:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 754361 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3wBXjN6qRhz9sDb for ; Tue, 25 Apr 2017 03:03:20 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="T50IlabX"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Z0MjW2nJ"; dkim-atps=neutral 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=ScjOsf3629NtX3lfh/xOz1zv/6v4aPa+YfklxYi2XYs=; b=T50IlabXVLkpITJDoyQbAHiW/j Vw2G7cDi6EaY6cP6lxLP/Pf/Hfqmyu40MD0usODV5Z8j/Z0nVYioGgV3PCUAdeG4uklSrd20xxLvM PR6aFf1OGUs0w8+WTnNOjjajLPqReJ2kNrwOd9wHlpnt3ZBbjGBCwbiou3dFRZFKgcEJTo7PnPnET CIxDUbejQdaDMYWlGFzOFpNr3UuxCNI3Gl/A6bnAJwxvTGEKG3qJmHYwZZzgr6Wr50HQEvExF10gb csuzKEN3szrvz2+dIRUIj6Q4uQmgvEGYjnUX967ftVCjCJfufwb5r9xpBHiaZN9ecXCxKnOsBbcLl w6UpbvsQ==; 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 1d2hOM-0005jg-PW; Mon, 24 Apr 2017 17:03:14 +0000 Received: from mail-pg0-x244.google.com ([2607:f8b0:400e:c05::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d2hNj-0004ig-Rs for linux-mtd@lists.infradead.org; Mon, 24 Apr 2017 17:02:45 +0000 Received: by mail-pg0-x244.google.com with SMTP id 34so5615343pgx.3 for ; Mon, 24 Apr 2017 10:02:18 -0700 (PDT) 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=CP+TPnKVVtOSrrvJ7u+KOqNK8cP/OTGg4qGDC5ecKK0=; b=Z0MjW2nJWuzwThiOJ+y13hmwk9vsv1WkVvg/5+sBTLVK88RzUFFYDKGre5pNhK1Y/j ex4+zeKEWVaw7QLgwfHGhXDtse8sGMgDwY4S20QTobVve35teGA/cmRU1koHTp/tYnHa uhXRb+ybt5De1hI09JkL3egCSv2fd9oLEYztaniHHl5R2pL7ydN5XsmEsuJODraSniSw IBpgkMwGNbkFPaRqhFqEvhsXzb633l8GY0xpU45nhFN5xLzrRzc+Ed8Zp/EpwbqeIjj2 LR741PeCaMTBE3jDmfqk8ZtBBbDxpwXHhG0y4xRDvq1y2In1ldDDER45L0uCbR7iYLwj 0VRA== 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=CP+TPnKVVtOSrrvJ7u+KOqNK8cP/OTGg4qGDC5ecKK0=; b=CqB8pp3GQY3RBwmkjRapOWPBw00DwKdh3RWj0fhjhby0uCIHt5jt2YDO/SMrsO/AZP jU8rAVnE3bA0aKYF91wurkqazA31WjvkRrSdfmnlSVi7LzgVnBr8yCyQbOGMwRbW6+iT aC/JPs+aww/E75oG40T60q+nu7aNR6PEacqdL0mb/yNdvIXAynLrMUctCBa2TEImDqkK 7drjEv21kcwDnNR8HZXjqEmxQfoie+nTrxoOMQ5Xbm0JWZES5DmM00EkKzHqEvvcDwvE e8EuxJi2M5rPVc6f2RxWdWsqLZNft2i7Oxv2DWqTgqqpO/SADIvknCVtzEMA4ydwRei3 +8gA== X-Gm-Message-State: AN3rC/43lFSfBeNgCk+iFV3KuI+NWqGtgyTzNdPhhMwRNLJtAgp3dJPm Kz8KSQD0bvMXJw== X-Received: by 10.99.8.193 with SMTP id 184mr25838380pgi.189.1493053338436; Mon, 24 Apr 2017 10:02:18 -0700 (PDT) Received: from ebiggers-linuxstation.kir.corp.google.com ([100.119.30.131]) by smtp.gmail.com with ESMTPSA id s89sm31927267pfi.79.2017.04.24.10.02.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 24 Apr 2017 10:02:17 -0700 (PDT) From: Eric Biggers To: linux-fscrypt@vger.kernel.org Subject: [PATCH 6/6] ext4: clean up ext4_match() and callers Date: Mon, 24 Apr 2017 10:00:13 -0700 Message-Id: <20170424170013.85175-7-ebiggers3@gmail.com> X-Mailer: git-send-email 2.12.2.816.g2cccc81164-goog In-Reply-To: <20170424170013.85175-1-ebiggers3@gmail.com> References: <20170424170013.85175-1-ebiggers3@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170424_100236_388437_B577F9DE X-CRM114-Status: GOOD ( 16.69 ) X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-1.8 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:400e:c05:0:0:0:244 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_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 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: hashimoto@chromium.org, Gwendal Grignou , "Theodore Y . Ts'o" , Eric Biggers , linux-f2fs-devel@lists.sourceforge.net, linux-mtd@lists.infradead.org, Jaegeuk Kim , linux-ext4@vger.kernel.org, kinaba@chromium.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Eric Biggers When ext4 encryption was originally merged, we were encrypting the user-specified filename in ext4_match(), introducing a lot of additional complexity into ext4_match() and its callers. This has since been changed to encrypt the filename earlier, so we can remove the gunk that's no longer needed. This more or less reverts ext4_search_dir() and ext4_find_dest_de() to the way they were in the v4.0 kernel. Signed-off-by: Eric Biggers --- fs/ext4/namei.c | 81 ++++++++++++++++++--------------------------------------- 1 file changed, 25 insertions(+), 56 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 6ecc3ae87a79..b6b8d073fdc4 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -1237,18 +1237,17 @@ static void dx_insert_block(struct dx_frame *frame, u32 hash, ext4_lblk_t block) } /* - * NOTE! unlike strncmp, ext4_match returns 1 for success, 0 for failure. + * Test whether a directory entry matches the filename being searched for. * - * `len <= EXT4_NAME_LEN' is guaranteed by caller. - * `de != NULL' is guaranteed by caller. + * Return: %true if the directory entry matches, otherwise %false. */ -static inline int ext4_match(struct ext4_filename *fname, - struct ext4_dir_entry_2 *de) +static inline bool ext4_match(const struct ext4_filename *fname, + const struct ext4_dir_entry_2 *de) { struct fscrypt_name f; if (!de->inode) - return 0; + return false; f.usr_fname = fname->usr_fname; f.disk_name = fname->disk_name; @@ -1269,48 +1268,31 @@ int ext4_search_dir(struct buffer_head *bh, char *search_buf, int buf_size, struct ext4_dir_entry_2 * de; char * dlimit; int de_len; - int res; de = (struct ext4_dir_entry_2 *)search_buf; dlimit = search_buf + buf_size; while ((char *) de < dlimit) { /* this code is executed quadratically often */ /* do minimal checking `by hand' */ - if ((char *) de + de->name_len <= dlimit) { - res = ext4_match(fname, de); - if (res < 0) { - res = -1; - goto return_result; - } - if (res > 0) { - /* found a match - just to be sure, do - * a full check */ - if (ext4_check_dir_entry(dir, NULL, de, bh, - bh->b_data, - bh->b_size, offset)) { - res = -1; - goto return_result; - } - *res_dir = de; - res = 1; - goto return_result; - } - + if ((char *) de + de->name_len <= dlimit && + ext4_match(fname, de)) { + /* found a match - just to be sure, do + * a full check */ + if (ext4_check_dir_entry(dir, NULL, de, bh, bh->b_data, + bh->b_size, offset)) + return -1; + *res_dir = de; + return 1; } /* prevent looping on a bad block */ de_len = ext4_rec_len_from_disk(de->rec_len, dir->i_sb->s_blocksize); - if (de_len <= 0) { - res = -1; - goto return_result; - } + if (de_len <= 0) + return -1; offset += de_len; de = (struct ext4_dir_entry_2 *) ((char *) de + de_len); } - - res = 0; -return_result: - return res; + return 0; } static int is_dx_internal_node(struct inode *dir, ext4_lblk_t block, @@ -1821,24 +1803,15 @@ int ext4_find_dest_de(struct inode *dir, struct inode *inode, int nlen, rlen; unsigned int offset = 0; char *top; - int res; de = (struct ext4_dir_entry_2 *)buf; top = buf + buf_size - reclen; while ((char *) de <= top) { if (ext4_check_dir_entry(dir, NULL, de, bh, - buf, buf_size, offset)) { - res = -EFSCORRUPTED; - goto return_result; - } - /* Provide crypto context and crypto buffer to ext4 match */ - res = ext4_match(fname, de); - if (res < 0) - goto return_result; - if (res > 0) { - res = -EEXIST; - goto return_result; - } + buf, buf_size, offset)) + return -EFSCORRUPTED; + if (ext4_match(fname, de)) + return -EEXIST; nlen = EXT4_DIR_REC_LEN(de->name_len); rlen = ext4_rec_len_from_disk(de->rec_len, buf_size); if ((de->inode ? rlen - nlen : rlen) >= reclen) @@ -1846,15 +1819,11 @@ int ext4_find_dest_de(struct inode *dir, struct inode *inode, de = (struct ext4_dir_entry_2 *)((char *)de + rlen); offset += rlen; } - if ((char *) de > top) - res = -ENOSPC; - else { - *dest_de = de; - res = 0; - } -return_result: - return res; + return -ENOSPC; + + *dest_de = de; + return 0; } int ext4_insert_dentry(struct inode *dir,