From patchwork Thu Oct 18 14:36:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 985973 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="o6WeBp+S"; 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 42bXGV5WMhz9sDn for ; Fri, 19 Oct 2018 01:57:54 +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=JPrR7mDx48tlrzhmGhdNCkYc8xN3HDJUV0X1F7n1MFg=; b=o6WeBp+S2iPKF/ V7nZdqBxRztokP91Sz71S6UVmfPvDummmLmKfJUVD7PHH6yMz5ML1aXDRkIdLuUYGYrlnvh9Y5/f/ HIfx+LVgsXszfzm1cej5yh6fWEqCHaDAhwNIjs9A4b8gHCUhiD2nRYc7RluKna271SJ0ZlWCPEVht GtHyz/u8xFbP127tyyOnNmRicvGvVX7mjN5HACdgoMvMHxW3sLD4HydSkm3YIfIyZr1KuYl6rDEV2 BoFD9R4ddf3YmRAH6S7oo/tTW64V/1OvDqrDjuNrySScJPPArsUKYSoi2dArGjJHIZ/45X0GAFcY4 Yb1OSYw8Fxb4mV3Wgx+Q==; 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 1gD9jz-0000FY-7N; Thu, 18 Oct 2018 14:57:35 +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-0004KS-98 for linux-mtd@lists.infradead.org; Thu, 18 Oct 2018 14:40:26 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 8238018011B63; Thu, 18 Oct 2018 16:38:26 +0200 (CEST) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 20/42] mkfs.ubifs: Seperate path encryption from symlink encryption helper Date: Thu, 18 Oct 2018 16:36:56 +0200 Message-Id: <20181018143718.26298-21-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_547441_707CF626 X-CRM114-Status: GOOD ( 12.96 ) 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 | 36 ++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c index 66ca061cc225..49a895ae3682 100644 --- a/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c +++ b/ubifs-utils/mkfs.ubifs/mkfs.ubifs.c @@ -1451,24 +1451,20 @@ static int set_fscrypt_context(struct ubifs_ino_node *host_ino, ino_t inum, fctx, sizeof(*fctx)); } -static int encrypt_symlink(void *dst, void *data, unsigned int data_len, - struct fscrypt_context *fctx) +static int encrypt_path(void **outbuf, void *data, unsigned int data_len, + unsigned int max_namelen, struct fscrypt_context *fctx) { - struct fscrypt_symlink_data *sd; - void *inbuf, *outbuf, *crypt_key; - unsigned int max_namelen = UBIFS_MAX_INO_DATA; + void *inbuf, *crypt_key; unsigned int padding = 4 << (fctx->flags & FS_POLICY_FLAGS_PAD_MASK); unsigned int cryptlen; - unsigned int link_disk_len = fscrypt_fname_encrypted_size(fctx, data_len) + sizeof(struct fscrypt_symlink_data); cryptlen = max_t(unsigned int, data_len, FS_CRYPTO_BLOCK_SIZE); cryptlen = round_up(cryptlen, padding); cryptlen = min(cryptlen, max_namelen); - sd = xzalloc(link_disk_len); inbuf = xmalloc(cryptlen); /* CTS mode needs a block size aligned buffer */ - outbuf = xmalloc(round_up(cryptlen, FS_CRYPTO_BLOCK_SIZE)); + *outbuf = xmalloc(round_up(cryptlen, FS_CRYPTO_BLOCK_SIZE)); memset(inbuf, 0, cryptlen); memcpy(inbuf, data, data_len); @@ -1476,16 +1472,34 @@ static int encrypt_symlink(void *dst, void *data, unsigned int data_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) + if (encrypt_aes128_cbc_cts(inbuf, cryptlen, crypt_key, *outbuf) < 0) return err_msg("could not encrypt filename"); + free(crypt_key); + free(inbuf); + return cryptlen; +} + +static int encrypt_symlink(void *dst, void *data, unsigned int data_len, + struct fscrypt_context *fctx) +{ + struct fscrypt_symlink_data *sd; + void *outbuf; + unsigned int link_disk_len = fscrypt_fname_encrypted_size(fctx, data_len) + sizeof(struct fscrypt_symlink_data); + unsigned int cryptlen; + int ret; + + ret = encrypt_path(&outbuf, data, data_len, UBIFS_MAX_INO_DATA, fctx); + if (ret < 0) + return ret; + cryptlen = ret; + + sd = xzalloc(link_disk_len); memcpy(sd->encrypted_path, outbuf, cryptlen); sd->len = cpu_to_le16(cryptlen); memcpy(dst, sd, link_disk_len); ((char *)dst)[link_disk_len - 1] = '\0'; - free(crypt_key); - free(inbuf); free(outbuf); free(sd); return link_disk_len;