From patchwork Thu Oct 18 14:36:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 986017 X-Patchwork-Delegate: david.oberhollenzer@sigma-star.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=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=nod.at Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="tNIL9zLE"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::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 42bXZM0J1fz9sC2 for ; Fri, 19 Oct 2018 02:11:39 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=9odpoV91vzKdEV77OifP03aA6c4Ct2WY5dUn+V+0pIY=; b=tNIL9zLEqYLiCv t/1B5XXR3jv1v988/LymibHHsmZF1zj9dxsMBTj+G82dIIlYMnsftS+PUnVwoZast3lKpJby5HJoc VKse/P0pRLnHpIcfY/m0Cq7RLg2wBMPRV2fSzVz0KHPm3gW14S2mLPq64TWu1K55O+ul1Of69FjeB g8k+R4kcCcVxpVShrS/d7DHCGteYqKC35u+K75QXrF6lBFV3oXeLH5to0O6aY7vRKL/XIHNgSHUlv lxx4FOjQeQ0ZGXqTpixoi4qafexObSpWdiI0RCLphDg+6duNUmq2nhqmY808oRJ9ogqmyzWkg12lH u8PBrhnxsFzQaoO+VwUg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gD9xP-0007Ue-Fw; Thu, 18 Oct 2018 15:11:27 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gD9Rv-0004MX-A6 for linux-mtd@lists.infradead.org; Thu, 18 Oct 2018 14:40:36 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 0824B18011B64; Thu, 18 Oct 2018 16:38:28 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 21/42] mkfs.ubifs: Cleanup add_dent_node, user path encryption helper Date: Thu, 18 Oct 2018 16:36:57 +0200 Message-Id: <20181018143718.26298-22-richard@nod.at> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181018143718.26298-1-richard@nod.at> References: <20181018143718.26298-1-richard@nod.at> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181018_073855_683959_012A675A X-CRM114-Status: GOOD ( 13.86 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) 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: Richard Weinberger , david.oberhollenzer@sigma-star.at Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: David Oberhollenzer Signed-off-by: David Oberhollenzer Signed-off-by: Richard Weinberger --- ubifs-utils/mkfs.ubifs/mkfs.ubifs.c | 55 ++++++++--------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c index 49a895ae3682..ae1d26726deb 100644 --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c @@ -1703,53 +1703,28 @@ static int add_dent_node(ino_t dir_inum, const char *name, ino_t inum, set_dent_cookie(dent); if (!fctx) { - dent_key_init(c, &key, dir_inum, dname.name, dname.len); - dent->nlen = cpu_to_le16(dname.len); - memcpy(dent->name, dname.name, dname.len); - dent->name[dname.len] = '\0'; - len = UBIFS_DENT_NODE_SZ + dname.len + 1; - kname_len = dname.len; kname = strdup(name); if (!kname) return err_msg("cannot allocate memory"); } else { - void *inbuf, *outbuf, *crypt_key; unsigned int max_namelen = type == UBIFS_ITYPE_LNK ? UBIFS_MAX_INO_DATA : UBIFS_MAX_NLEN; - unsigned int padding = 4 << (fctx->flags & FS_POLICY_FLAGS_PAD_MASK); - unsigned int cryptlen; - - cryptlen = max_t(unsigned int, dname.len, FS_CRYPTO_BLOCK_SIZE); - cryptlen = round_up(cryptlen, padding); - cryptlen = min(cryptlen, max_namelen); - - inbuf = xmalloc(cryptlen); - /* CTS mode needs a block size aligned buffer */ - outbuf = xmalloc(round_up(cryptlen, FS_CRYPTO_BLOCK_SIZE)); - - memset(inbuf, 0, cryptlen); - memcpy(inbuf, dname.name, dname.len); - - crypt_key = calc_fscrypt_subkey(fctx); - if (!crypt_key) - return err_msg("could not compute subkey"); - if (encrypt_aes128_cbc_cts(inbuf, cryptlen, crypt_key, outbuf) < 0) - return err_msg("could not encrypt filename"); - - dent->nlen = cpu_to_le16(cryptlen); - memcpy(dent->name, outbuf, cryptlen); - dent->name[cryptlen] = '\0'; - len = UBIFS_DENT_NODE_SZ + cryptlen + 1; - - dent_key_init(c, &key, dir_inum, outbuf, cryptlen); - - kname_len = cryptlen; - kname = xmalloc(cryptlen); - memcpy(kname, outbuf, cryptlen); - free(crypt_key); - free(inbuf); - free(outbuf); + int ret; + + ret = encrypt_path((void **)&kname, dname.name, dname.len, + max_namelen, fctx); + if (ret < 0) + return ret; + + kname_len = ret; } + + dent_key_init(c, &key, dir_inum, kname, kname_len); + dent->nlen = cpu_to_le16(kname_len); + memcpy(dent->name, kname, kname_len); + dent->name[kname_len] = '\0'; + len = UBIFS_DENT_NODE_SZ + kname_len + 1; + key_write(&key, dent->key); return add_node(&key, kname, kname_len, dent, len);