linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Sascha Hauer <s.hauer@pengutronix.de>,
	Eric Biggers <ebiggers@google.com>,
	Richard Weinberger <richard@nod.at>,
	Sasha Levin <sashal@kernel.org>
Subject: [PATCH 5.4 006/111] ubifs: fix wrong use of crypto_shash_descsize()
Date: Tue, 26 May 2020 20:52:24 +0200	[thread overview]
Message-ID: <20200526183933.076367163@linuxfoundation.org> (raw)
In-Reply-To: <20200526183932.245016380@linuxfoundation.org>

From: Eric Biggers <ebiggers@google.com>

[ Upstream commit 3c3c32f85b6cc05e5db78693457deff03ac0f434 ]

crypto_shash_descsize() returns the size of the shash_desc context
needed to compute the hash, not the size of the hash itself.

crypto_shash_digestsize() would be correct, or alternatively using
c->hash_len and c->hmac_desc_len which already store the correct values.
But actually it's simpler to just use stack arrays, so do that instead.

Fixes: 49525e5eecca ("ubifs: Add helper functions for authentication support")
Fixes: da8ef65f9573 ("ubifs: Authenticate replayed journal")
Cc: <stable@vger.kernel.org> # v4.20+
Cc: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Eric Biggers <ebiggers@google.com>
Acked-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 fs/ubifs/auth.c   | 17 ++++-------------
 fs/ubifs/replay.c | 13 ++-----------
 2 files changed, 6 insertions(+), 24 deletions(-)

diff --git a/fs/ubifs/auth.c b/fs/ubifs/auth.c
index 8cdbd53d780c..f985a3fbbb36 100644
--- a/fs/ubifs/auth.c
+++ b/fs/ubifs/auth.c
@@ -79,13 +79,9 @@ int ubifs_prepare_auth_node(struct ubifs_info *c, void *node,
 			     struct shash_desc *inhash)
 {
 	struct ubifs_auth_node *auth = node;
-	u8 *hash;
+	u8 hash[UBIFS_HASH_ARR_SZ];
 	int err;
 
-	hash = kmalloc(crypto_shash_descsize(c->hash_tfm), GFP_NOFS);
-	if (!hash)
-		return -ENOMEM;
-
 	{
 		SHASH_DESC_ON_STACK(hash_desc, c->hash_tfm);
 
@@ -94,21 +90,16 @@ int ubifs_prepare_auth_node(struct ubifs_info *c, void *node,
 
 		err = crypto_shash_final(hash_desc, hash);
 		if (err)
-			goto out;
+			return err;
 	}
 
 	err = ubifs_hash_calc_hmac(c, hash, auth->hmac);
 	if (err)
-		goto out;
+		return err;
 
 	auth->ch.node_type = UBIFS_AUTH_NODE;
 	ubifs_prepare_node(c, auth, ubifs_auth_node_sz(c), 0);
-
-	err = 0;
-out:
-	kfree(hash);
-
-	return err;
+	return 0;
 }
 
 static struct shash_desc *ubifs_get_desc(const struct ubifs_info *c,
diff --git a/fs/ubifs/replay.c b/fs/ubifs/replay.c
index b28ac4dfb407..01fcf7975047 100644
--- a/fs/ubifs/replay.c
+++ b/fs/ubifs/replay.c
@@ -601,18 +601,12 @@ static int authenticate_sleb(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
 	struct ubifs_scan_node *snod;
 	int n_nodes = 0;
 	int err;
-	u8 *hash, *hmac;
+	u8 hash[UBIFS_HASH_ARR_SZ];
+	u8 hmac[UBIFS_HMAC_ARR_SZ];
 
 	if (!ubifs_authenticated(c))
 		return sleb->nodes_cnt;
 
-	hash = kmalloc(crypto_shash_descsize(c->hash_tfm), GFP_NOFS);
-	hmac = kmalloc(c->hmac_desc_len, GFP_NOFS);
-	if (!hash || !hmac) {
-		err = -ENOMEM;
-		goto out;
-	}
-
 	list_for_each_entry(snod, &sleb->nodes, list) {
 
 		n_nodes++;
@@ -662,9 +656,6 @@ static int authenticate_sleb(struct ubifs_info *c, struct ubifs_scan_leb *sleb,
 		err = 0;
 	}
 out:
-	kfree(hash);
-	kfree(hmac);
-
 	return err ? err : n_nodes - n_not_auth;
 }
 
-- 
2.25.1




  parent reply	other threads:[~2020-05-26 19:07 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-26 18:52 [PATCH 5.4 000/111] 5.4.43-rc1 review Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 001/111] i2c: dev: Fix the race between the release of i2c_dev and cdev Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 002/111] KVM: SVM: Fix potential memory leak in svm_cpu_init() Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 003/111] ima: Set file->f_mode instead of file->f_flags in ima_calc_file_hash() Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 004/111] evm: Check also if *tfm is an error pointer in init_desc() Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 005/111] ima: Fix return value of ima_write_policy() Greg Kroah-Hartman
2020-05-26 18:52 ` Greg Kroah-Hartman [this message]
2020-05-26 18:52 ` [PATCH 5.4 007/111] ACPI: EC: PM: Avoid flushing EC work when EC GPE is inactive Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 008/111] mtd: spinand: Propagate ECC information to the MTD structure Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 009/111] fix multiplication overflow in copy_fdtable() Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 010/111] ubifs: remove broken lazytime support Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 011/111] i2c: fix missing pm_runtime_put_sync in i2c_device_probe Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 012/111] iommu/amd: Fix over-read of ACPI UID from IVRS table Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 013/111] evm: Fix a small race in init_desc() Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 014/111] i2c: mux: demux-pinctrl: Fix an error handling path in i2c_demux_pinctrl_probe() Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 015/111] ubi: Fix seq_file usage in detailed_erase_block_info debugfs file Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 016/111] afs: Dont unlock fetched data pages until the op completes successfully Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 017/111] mtd: Fix mtd not registered due to nvmem name collision Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 018/111] kbuild: avoid concurrency issue in parallel building dtbs and dtbs_check Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 019/111] net: drop_monitor: use IS_REACHABLE() to guard net_dm_hw_report() Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 020/111] gcc-common.h: Update for GCC 10 Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 021/111] HID: multitouch: add eGalaxTouch P80H84 support Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 022/111] HID: alps: Add AUI1657 device ID Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 023/111] HID: alps: ALPS_1657 is too specific; use U1_UNICORN_LEGACY instead Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 024/111] scsi: qla2xxx: Fix hang when issuing nvme disconnect-all in NPIV Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 025/111] scsi: qla2xxx: Delete all sessions before unregister local nvme port Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 026/111] configfs: fix config_item refcnt leak in configfs_rmdir() Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 027/111] vhost/vsock: fix packet delivery order to monitoring devices Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 028/111] aquantia: Fix the media type of AQC100 ethernet controller in the driver Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 029/111] component: Silence bind error on -EPROBE_DEFER Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 030/111] net/ena: Fix build warning in ena_xdp_set() Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 031/111] scsi: ibmvscsi: Fix WARN_ON during event pool release Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 032/111] HID: i2c-hid: reset Synaptics SYNA2393 on resume Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 033/111] x86/mm/cpa: Flush direct map alias during cpa Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 034/111] ibmvnic: Skip fatal error reset after passive init Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 035/111] ftrace/selftest: make unresolved cases cause failure if --fail-unresolved set Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 036/111] x86/apic: Move TSC deadline timer debug printk Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 037/111] gtp: set NLM_F_MULTI flag in gtp_genl_dump_pdp() Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 038/111] HID: quirks: Add HID_QUIRK_NO_INIT_REPORTS quirk for Dell K12A keyboard-dock Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 039/111] ceph: fix double unlock in handle_cap_export() Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 040/111] stmmac: fix pointer check after utilization in stmmac_interrupt Greg Kroah-Hartman
2020-05-26 18:52 ` [PATCH 5.4 041/111] USB: core: Fix misleading driver bug report Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 042/111] platform/x86: asus-nb-wmi: Do not load on Asus T100TA and T200TA Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 043/111] iommu/amd: Call domain_flush_complete() in update_domain() Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 044/111] drm/amd/display: Prevent dpcd reads with passive dongles Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 045/111] KVM: selftests: Fix build for evmcs.h Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 046/111] ARM: futex: Address build warning Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 047/111] scripts/gdb: repair rb_first() and rb_last() Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 048/111] ALSA: hda - constify and cleanup static NodeID tables Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 049/111] ALSA: hda: patch_realtek: fix empty macro usage in if block Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 050/111] ALSA: hda: Manage concurrent reg access more properly Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 051/111] ALSA: hda/realtek - Add supported new mute Led for HP Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 052/111] ALSA: hda/realtek - Add HP new mute led supported for ALC236 Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 053/111] ALSA: hda/realtek: Add quirk for Samsung Notebook Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 054/111] ALSA: hda/realtek - Enable headset mic of ASUS GL503VM with ALC295 Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 055/111] ALSA: hda/realtek - Enable headset mic of ASUS UX550GE " Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 056/111] ALSA: hda/realtek: Enable headset mic of ASUS UX581LV " Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 057/111] KVM: x86: Fix pkru save/restore when guest CR4.PKE=0, move it to x86.c Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 058/111] ALSA: iec1712: Initialize STDSP24 properly when using the model=staudio option Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 059/111] ALSA: pcm: fix incorrect hw_base increase Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 060/111] ALSA: hda/realtek - Fix silent output on Gigabyte X570 Aorus Xtreme Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 061/111] ALSA: hda/realtek - Add more fixup entries for Clevo machines Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 062/111] scsi: qla2xxx: Do not log message when reading port speed via sysfs Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 063/111] scsi: target: Put lun_ref at end of tmr processing Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 064/111] arm64: Fix PTRACE_SYSEMU semantics Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 065/111] drm/etnaviv: fix perfmon domain interation Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 066/111] apparmor: Fix use-after-free in aa_audit_rule_init Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 067/111] apparmor: fix potential label refcnt leak in aa_change_profile Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 068/111] apparmor: Fix aa_label refcnt leak in policy_update Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 069/111] dmaengine: tegra210-adma: Fix an error handling path in tegra_adma_probe() Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 070/111] drm/etnaviv: Fix a leak in submit_pin_objects() Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 071/111] dmaengine: dmatest: Restore default for channel Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 072/111] dmaengine: owl: Use correct lock in owl_dma_get_pchan() Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 073/111] vsprintf: dont obfuscate NULL and error pointers Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 074/111] drm/i915/gvt: Init DPLL/DDI vreg for virtual display instead of inheritance Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 075/111] drm/i915: Propagate error from completed fences Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 076/111] powerpc: Remove STRICT_KERNEL_RWX incompatibility with RELOCATABLE Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 077/111] powerpc/64s: Disable STRICT_KERNEL_RWX Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 078/111] bpf: Avoid setting bpf insns pages read-only when prog is jited Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 079/111] kbuild: Remove debug info from kallsyms linking Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 080/111] Revert "gfs2: Dont demote a glock until its revokes are written" Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 081/111] media: fdp1: Fix R-Car M3-N naming in debug message Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 082/111] staging: iio: ad2s1210: Fix SPI reading Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 083/111] staging: kpc2000: fix error return code in kp2000_pcie_probe() Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 084/111] staging: greybus: Fix uninitialized scalar variable Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 085/111] iio: sca3000: Remove an erroneous get_device() Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 086/111] iio: dac: vf610: Fix an error handling path in vf610_dac_probe() Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 087/111] iio: adc: ti-ads8344: Fix channel selection Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 088/111] misc: rtsx: Add short delay after exit from ASPM Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 089/111] tty: serial: add missing spin_lock_init for SiFive serial console Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 090/111] mei: release me_cl object reference Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 091/111] ipack: tpci200: fix error return code in tpci200_register() Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 092/111] s390/pci: Fix s390_mmio_read/write with MIO Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 093/111] s390/kaslr: add support for R_390_JMP_SLOT relocation type Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 094/111] device-dax: dont leak kernel memory to user space after unloading kmem Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 095/111] rapidio: fix an error in get_user_pages_fast() error handling Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 096/111] kasan: disable branch tracing for core runtime Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 097/111] rxrpc: Fix the excessive initial retransmission timeout Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 098/111] rxrpc: Fix a memory leak in rxkad_verify_response() Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 099/111] s390/kexec_file: fix initrd location for kdump kernel Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 100/111] flow_dissector: Drop BPF flow dissector prog ref on netns cleanup Greg Kroah-Hartman
2020-05-26 18:53 ` [PATCH 5.4 101/111] x86/unwind/orc: Fix unwind_get_return_address_ptr() for inactive tasks Greg Kroah-Hartman
2020-05-26 18:54 ` [PATCH 5.4 102/111] iio: adc: stm32-adc: Use dma_request_chan() instead dma_request_slave_channel() Greg Kroah-Hartman
2020-05-26 18:54 ` [PATCH 5.4 103/111] iio: adc: stm32-adc: fix device used to request dma Greg Kroah-Hartman
2020-05-26 18:54 ` [PATCH 5.4 104/111] iio: adc: stm32-dfsdm: Use dma_request_chan() instead dma_request_slave_channel() Greg Kroah-Hartman
2020-05-26 18:54 ` [PATCH 5.4 105/111] iio: adc: stm32-dfsdm: fix device used to request dma Greg Kroah-Hartman
2020-05-26 18:54 ` [PATCH 5.4 106/111] rxrpc: Trace discarded ACKs Greg Kroah-Hartman
2020-05-26 18:54 ` [PATCH 5.4 107/111] rxrpc: Fix ack discard Greg Kroah-Hartman
2020-05-26 18:54 ` [PATCH 5.4 108/111] tpm: check event log version before reading final events Greg Kroah-Hartman
2020-05-26 18:54 ` [PATCH 5.4 109/111] sched/fair: Reorder enqueue/dequeue_task_fair path Greg Kroah-Hartman
2020-05-26 18:54 ` [PATCH 5.4 110/111] sched/fair: Fix reordering of enqueue/dequeue_task_fair() Greg Kroah-Hartman
2020-05-26 18:54 ` [PATCH 5.4 111/111] sched/fair: Fix enqueue_task_fair() warning some more Greg Kroah-Hartman
2020-05-27  8:25 ` [PATCH 5.4 000/111] 5.4.43-rc1 review Naresh Kamboju
2020-05-27  8:34 ` Jon Hunter
2020-05-27 13:53 ` Guenter Roeck
2020-05-27 16:34 ` shuah

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200526183933.076367163@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=ebiggers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=richard@nod.at \
    --cc=s.hauer@pengutronix.de \
    --cc=sashal@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).