Skip to content

Commit 35a3bb3

Browse files
Aaron Sierraherbertx
authored andcommitted
crypto: talitos - Prevent panic in probe error path
The probe error path for this driver, for all intents and purposes, is the talitos_remove() function due to the common "goto err_out". Without this patch applied, talitos_remove() will panic under these two conditions: 1. If the RNG device hasn't been registered via talitos_register_rng() prior to entry into talitos_remove(), then the attempt to unregister the RNG "device" will cause a panic. 2. If the priv->chan array has not been allocated prior to entry into talitos_remove(), then the per-channel FIFO cleanup will panic because of the dereference of that NULL "array". Both of the above scenarios occur if talitos_probe_irq() fails. This patch resolves issue #1 by introducing a boolean to mask the hwrng_unregister() call in talitos_unregister_rng() if RNG device registration was unsuccessful. It resolves issue #2 by checking that priv->chan is not NULL in the per-channel FIFO cleanup for loop. Signed-off-by: Aaron Sierra <asierra@xes-inc.com> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
1 parent ab86ca0 commit 35a3bb3

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

drivers/crypto/talitos.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,21 +766,30 @@ static int talitos_rng_init(struct hwrng *rng)
766766
static int talitos_register_rng(struct device *dev)
767767
{
768768
struct talitos_private *priv = dev_get_drvdata(dev);
769+
int err;
769770

770771
priv->rng.name = dev_driver_string(dev),
771772
priv->rng.init = talitos_rng_init,
772773
priv->rng.data_present = talitos_rng_data_present,
773774
priv->rng.data_read = talitos_rng_data_read,
774775
priv->rng.priv = (unsigned long)dev;
775776

776-
return hwrng_register(&priv->rng);
777+
err = hwrng_register(&priv->rng);
778+
if (!err)
779+
priv->rng_registered = true;
780+
781+
return err;
777782
}
778783

779784
static void talitos_unregister_rng(struct device *dev)
780785
{
781786
struct talitos_private *priv = dev_get_drvdata(dev);
782787

788+
if (!priv->rng_registered)
789+
return;
790+
783791
hwrng_unregister(&priv->rng);
792+
priv->rng_registered = false;
784793
}
785794

786795
/*
@@ -2673,7 +2682,7 @@ static int talitos_remove(struct platform_device *ofdev)
26732682
if (hw_supports(dev, DESC_HDR_SEL0_RNG))
26742683
talitos_unregister_rng(dev);
26752684

2676-
for (i = 0; i < priv->num_channels; i++)
2685+
for (i = 0; priv->chan && i < priv->num_channels; i++)
26772686
kfree(priv->chan[i].fifo);
26782687

26792688
kfree(priv->chan);

drivers/crypto/talitos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ struct talitos_private {
149149

150150
/* hwrng device */
151151
struct hwrng rng;
152+
bool rng_registered;
152153
};
153154

154155
extern int talitos_submit(struct device *dev, int ch, struct talitos_desc *desc,

0 commit comments

Comments
 (0)