All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org,
	"Fabio Estevam" <fabio.estevam@freescale.com>,
	"Marek Vasut" <marex@denx.de>,
	"Herbert Xu" <herbert@gondor.apana.org.au>,
	"Tom Lendacky" <thomas.lendacky@amd.com>,
	"David S. Miller" <davem@davemloft.net>,
	"Shawn Guo" <shawn.guo@linaro.org>
Subject: [PATCH 3.2 087/101] crypto: hash - Simplify the ahash_finup implementation
Date: Thu, 01 Jun 2017 16:40:55 +0100	[thread overview]
Message-ID: <lsq.1496331655.106992874@decadent.org.uk> (raw)
In-Reply-To: <lsq.1496331653.552489284@decadent.org.uk>

3.2.89-rc1 review patch.  If anyone has any objections, please let me know.

------------------

From: Marek Vasut <marex@denx.de>

commit d4a7a0fbe959e12bdd071b79b50ed34853a6db8f upstream.

The ahash_def_finup() can make use of the request save/restore functions,
thus make it so. This simplifies the code a little and unifies the code
paths.

Note that the same remark about free()ing the req->priv applies here, the
req->priv can only be free()'d after the original request was restored.

Finally, squash a bug in the invocation of completion in the ASYNC path.
In both ahash_def_finup_done{1,2}, the function areq->base.complete(X, err);
was called with X=areq->base.data . This is incorrect , as X=&areq->base
is the correct value. By analysis of the data structures, we see the areq is
of type 'struct ahash_request' , areq->base is of type 'struct crypto_async_request'
and areq->base.completion is of type crypto_completion_t, which is defined in
include/linux/crypto.h as:

  typedef void (*crypto_completion_t)(struct crypto_async_request *req, int err);

This is one lead that the X should be &areq->base . Next up, we can inspect
other code which calls the completion callback to give us kind-of statistical
idea of how this callback is used. We can try:

  $ git grep base\.complete\( drivers/crypto/

Finally, by inspecting ahash_request_set_callback() implementation defined
in include/crypto/hash.h , we observe that the .data entry of 'struct
crypto_async_request' is intended for arbitrary data, not for completion
argument.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: David S. Miller <davem@davemloft.net>
Cc: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>
Cc: Shawn Guo <shawn.guo@linaro.org>
Cc: Tom Lendacky <thomas.lendacky@amd.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 crypto/ahash.c | 36 +++++++++---------------------------
 1 file changed, 9 insertions(+), 27 deletions(-)

--- a/crypto/ahash.c
+++ b/crypto/ahash.c
@@ -350,19 +350,16 @@ static void ahash_def_finup_finish2(stru
 		memcpy(priv->result, req->result,
 		       crypto_ahash_digestsize(crypto_ahash_reqtfm(req)));
 
-	kzfree(priv);
+	ahash_restore_req(req);
 }
 
 static void ahash_def_finup_done2(struct crypto_async_request *req, int err)
 {
 	struct ahash_request *areq = req->data;
-	struct ahash_request_priv *priv = areq->priv;
-	crypto_completion_t complete = priv->complete;
-	void *data = priv->data;
 
 	ahash_def_finup_finish2(areq, err);
 
-	complete(data, err);
+	areq->base.complete(&areq->base, err);
 }
 
 static int ahash_def_finup_finish1(struct ahash_request *req, int err)
@@ -382,38 +379,23 @@ out:
 static void ahash_def_finup_done1(struct crypto_async_request *req, int err)
 {
 	struct ahash_request *areq = req->data;
-	struct ahash_request_priv *priv = areq->priv;
-	crypto_completion_t complete = priv->complete;
-	void *data = priv->data;
 
 	err = ahash_def_finup_finish1(areq, err);
 
-	complete(data, err);
+	areq->base.complete(&areq->base, err);
 }
 
 static int ahash_def_finup(struct ahash_request *req)
 {
 	struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
-	unsigned long alignmask = crypto_ahash_alignmask(tfm);
-	unsigned int ds = crypto_ahash_digestsize(tfm);
-	struct ahash_request_priv *priv;
-
-	priv = kmalloc(sizeof(*priv) + ahash_align_buffer_size(ds, alignmask),
-		       (req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP) ?
-		       GFP_KERNEL : GFP_ATOMIC);
-	if (!priv)
-		return -ENOMEM;
-
-	priv->result = req->result;
-	priv->complete = req->base.complete;
-	priv->data = req->base.data;
-
-	req->result = PTR_ALIGN((u8 *)priv->ubuf, alignmask + 1);
-	req->base.complete = ahash_def_finup_done1;
-	req->base.data = req;
-	req->priv = priv;
+	int err;
 
-	return ahash_def_finup_finish1(req, tfm->update(req));
+	err = ahash_save_req(req, ahash_def_finup_done1);
+	if (err)
+		return err;
+
+	err = tfm->update(req);
+	return ahash_def_finup_finish1(req, err);
 }
 
 static int ahash_no_export(struct ahash_request *req, void *out)

  parent reply	other threads:[~2017-06-01 15:43 UTC|newest]

Thread overview: 105+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-01 15:40 [PATCH 3.2 000/101] 3.2.89-rc1 review Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 032/101] USB: serial: digi_acceleport: fix OOB-event processing Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 031/101] USB: serial: digi_acceleport: fix OOB data sanity check Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 049/101] powerpc/xmon: Fix data-breakpoint Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 043/101] KEYS: Fix an error code in request_master_key() Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 066/101] ALSA: timer: Reject user params with too small ticks Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 033/101] USB: serial: digi_acceleport: fix incomplete rx sanity check Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 039/101] serial: 8250_pci: Add MKS Tenta SCOM-0800 and SCOM-0801 cards Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 020/101] usb: dwc3: gadget: skip Set/Clear Halt when invalid Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 056/101] nfsd: special case truncates some more Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 023/101] USB: serial: ftdi_sio: fix extreme low-latency setting Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 029/101] bcma: use (get|put)_device when probing/removing device driver Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 024/101] drm/ttm: Make sure BOs being swapped out are cacheable Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 046/101] md linear: fix a race between linear_add() and linear_congested() Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 045/101] mmc: host: omap_hsmmc: avoid possible overflow of timeout value Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 074/101] xfrm_user: validate XFRM_MSG_NEWAE XFRMA_REPLAY_ESN_VAL replay_window Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 021/101] usb: gadget: f_hid: Use spinlock instead of mutex Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 060/101] net/dccp: fix use after free in tw_timer_handler() Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 079/101] net/packet: fix overflow in check for priv area size Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 093/101] nfsd: stricter decoding of write-like NFSv2/v3 ops Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 082/101] KEYS: fix keyctl_set_reqkey_keyring() to not leak thread keyrings Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 061/101] scsi: aacraid: Fix memory leak in fib init path Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 075/101] xfrm_user: validate XFRM_MSG_NEWAE incoming ESN size harder Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 055/101] nfsd: minor nfsd_setattr cleanup Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 092/101] nfsd4: minor NFSv2/v3 write decoding cleanup Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 014/101] USB: serial: mct_u232: fix modem-status error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 051/101] MIPS: Fix special case in 64 bit IP checksumming Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 009/101] USB: serial: ark3116: fix open error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 089/101] tracing: Use strlcpy() instead of strcpy() in __trace_find_cmdline() Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 080/101] net/packet: fix overflow in check for tp_frame_nr Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 018/101] perf script: Fix man page about --dump-raw-trace option Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 085/101] crypto: hash - Fix the pointer voodoo in unaligned ahash Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 016/101] USB: serial: ti_usb_3410_5052: fix control-message error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 071/101] KEYS: Reinstate EPERM for a key type name beginning with a '.' Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 006/101] IB/ipoib: Change list_del to list_del_init in the tx object Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 040/101] USB: serial: cp210x: add new IDs for GE Bx50v3 boards Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 078/101] packet: handle too big packets for PACKET_V3 Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 003/101] ath5k: drop bogus warning on drv_set_key with unsupported cipher Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 026/101] ext4: trim allocation requests to group size Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 035/101] s390/qdio: clear DSCI prior to scanning multiple input queues Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 042/101] USB: serial: mos7840: fix another NULL-deref at open Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 070/101] KEYS: special dot prefixed keyring name bug fix Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 038/101] ext4: preserve the needs_recovery flag when the journal is aborted Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 001/101] adm80211: return an error if adm8211_alloc_rings() fails Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 012/101] USB: serial: io_edgeport: fix epic-descriptor handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 017/101] staging: rtl: fix possible NULL pointer dereference Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 095/101] USB: serial: io_ti: fix information leak in completion handler Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 076/101] drm/vmwgfx: NULL pointer dereference in vmw_surface_define_ioctl() Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 004/101] RDMA/core: Fix incorrect structure packing for booleans Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 057/101] NFSv4: Fix the underestimation of delegation XDR space reservation Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 096/101] USB: serial: omninet: fix reference leaks at open Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 067/101] ALSA: ctxfi: Fallback DMA mask to 32bit Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 050/101] Bluetooth: Add another AR3012 04ca:3018 device Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 044/101] drivers: hv: Turn off write permission on the hypercall page Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 037/101] jbd2: don't leak modified metadata buffers on an aborted journal Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 081/101] net/packet: fix overflow in check for tp_reserve Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 099/101] sctp: do not inherit ipv6_{mc|ac|fl}_list from parent Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 098/101] ipv6: Check ip6_find_1stfragopt() return value properly Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 058/101] fuse: add missing FR_FORCE Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 027/101] ext4: use private version of page_zero_new_buffers() for data=journal mode Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 041/101] USB: serial: ftdi_sio: fix line-status over-reporting Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 010/101] USB: serial: ftdi_sio: fix modem-status error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 028/101] ext4: fix data corruption in data=journal mode Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 052/101] MIPS: OCTEON: Fix copy_from_user fault handling for large buffers Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 063/101] NFSv4: Fix range checking in __nfs4_get_acl_uncached and __nfs4_proc_set_acl Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 083/101] mm/mempolicy.c: fix error handling in set_mempolicy and mbind Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 062/101] scsi: aacraid: Reorder Adapter status check Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 077/101] drm/vmwgfx: fix integer overflow in vmw_surface_define_ioctl() Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 002/101] tty: serial: msm: Fix module autoload Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 091/101] nfsd: check for oversized NFSv2/v3 arguments Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 084/101] crypto: ahash - Fully restore ahash request before completing Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 030/101] [media] media: fix dm1105.c build error Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 015/101] USB: serial: ssu100: fix control-message error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 068/101] ALSA: seq: Fix link corruption by event " Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 086/101] crypto: hash - Pull out the functions to save/restore request Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 007/101] USB: serial: ch341: fix modem-status handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 072/101] KEYS: Disallow keyrings beginning with '.' to be joined as session keyrings Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 013/101] USB: serial: io_edgeport: fix descriptor error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 069/101] USB: iowarrior: fix NULL-deref at probe Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 025/101] drm/radeon: handle vfct with multiple vbios images Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 048/101] nlm: Ensure callback code also checks that the files match Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 064/101] NFSv4: fix getacl ERANGE for some ACL buffer sizes Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 034/101] USB: serial: keyspan_pda: fix receive sanity checks Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 008/101] USB: serial: ark3116: fix register-accessor error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 005/101] IB/ipoib: Set device connection mode only when needed Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 101/101] ipv6: fix out of bound writes in __ip6_append_data() Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 100/101] ipv6/dccp: do not inherit ipv6_mc_list from parent Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 011/101] USB: serial: ftdi_sio: fix latency-timer error handling Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 065/101] net sched actions: decrement module reference count after table flush Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 047/101] md: ensure md devices are freed before module is unloaded Ben Hutchings
2017-06-01 15:40 ` Ben Hutchings [this message]
2017-06-01 15:40 ` [PATCH 3.2 059/101] rdma_cm: fail iwarp accepts w/o connection params Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 053/101] MIPS: ip27: Disable qlge driver in defconfig Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 036/101] x86/pci-calgary: Fix iommu_free() comparison of unsigned expression >= 0 Ben Hutchings
2017-06-01 15:40   ` Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 090/101] ipx: call ipxitf_put() in ioctl error path Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 094/101] dccp/tcp: do not inherit mc_list from parent Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 097/101] ipv6: Prevent overrun when parsing v6 header options Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 073/101] ping: implement proper locking Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 019/101] mwifiex: debugfs: Fix (sometimes) off-by-1 SSID print Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 088/101] crypto: ahash - Fix EINPROGRESS notification callback Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 022/101] MIPS: 'make -s' should be silent Ben Hutchings
2017-06-01 15:40 ` [PATCH 3.2 054/101] nfsd: update mtime on truncate Ben Hutchings
2017-06-01 21:41 ` [PATCH 3.2 000/101] 3.2.89-rc1 review Guenter Roeck
2017-06-01 21:59   ` Ben Hutchings

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=lsq.1496331655.106992874@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=fabio.estevam@freescale.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marex@denx.de \
    --cc=shawn.guo@linaro.org \
    --cc=stable@vger.kernel.org \
    --cc=thomas.lendacky@amd.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.