Linux-Crypto Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH] crypto: chelsio - remove extra allocation for chtls_dev
@ 2020-01-24 22:20 Stephen Kitt
  2020-02-13  5:47 ` Herbert Xu
  2020-02-22  1:40 ` Herbert Xu
  0 siblings, 2 replies; 4+ messages in thread
From: Stephen Kitt @ 2020-01-24 22:20 UTC (permalink / raw)
  To: Atul Gupta, Herbert Xu, David S . Miller
  Cc: linux-crypto, linux-kernel, Stephen Kitt

chtls_uld_add allocates room for info->nports net_device structs
following the chtls_dev struct, presumably because it was originally
intended that the ports array would be stored there. This is suggested
by the assignment which was present in initial versions and removed by
c4e848586cf1 ("crypto: chelsio - remove redundant assignment to
cdev->ports"):

	cdev->ports = (struct net_device **)(cdev + 1);

This assignment was never used, being overwritten by lldi->ports
immediately afterwards, and I couldn't find any uses of the memory
allocated past the end of the struct.

Signed-off-by: Stephen Kitt <steve@sk2.org>
---
 drivers/crypto/chelsio/chtls/chtls_main.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/crypto/chelsio/chtls/chtls_main.c b/drivers/crypto/chelsio/chtls/chtls_main.c
index 18996935d8ba..1311488be37d 100644
--- a/drivers/crypto/chelsio/chtls/chtls_main.c
+++ b/drivers/crypto/chelsio/chtls/chtls_main.c
@@ -230,8 +230,7 @@ static void *chtls_uld_add(const struct cxgb4_lld_info *info)
 	struct chtls_dev *cdev;
 	int i, j;
 
-	cdev = kzalloc(sizeof(*cdev) + info->nports *
-		      (sizeof(struct net_device *)), GFP_KERNEL);
+	cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
 	if (!cdev)
 		goto out;
 
-- 
2.24.1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: chelsio - remove extra allocation for chtls_dev
  2020-01-24 22:20 [PATCH] crypto: chelsio - remove extra allocation for chtls_dev Stephen Kitt
@ 2020-02-13  5:47 ` Herbert Xu
  2020-02-14  8:10   ` Vinay Kumar Yadav
  2020-02-22  1:40 ` Herbert Xu
  1 sibling, 1 reply; 4+ messages in thread
From: Herbert Xu @ 2020-02-13  5:47 UTC (permalink / raw)
  To: Stephen Kitt, David S. Miller
  Cc: Atul Gupta, linux-crypto, linux-kernel, Vinay Kumar Yadav, netdev

On Fri, Jan 24, 2020 at 11:20:51PM +0100, Stephen Kitt wrote:
> chtls_uld_add allocates room for info->nports net_device structs
> following the chtls_dev struct, presumably because it was originally
> intended that the ports array would be stored there. This is suggested
> by the assignment which was present in initial versions and removed by
> c4e848586cf1 ("crypto: chelsio - remove redundant assignment to
> cdev->ports"):
> 
> 	cdev->ports = (struct net_device **)(cdev + 1);
> 
> This assignment was never used, being overwritten by lldi->ports
> immediately afterwards, and I couldn't find any uses of the memory
> allocated past the end of the struct.
> 
> Signed-off-by: Stephen Kitt <steve@sk2.org>

Thanks for the patch!

I think the problem goes deeper though.  It appears that instead
of allocating a ports array this function actually hangs onto the
array from the function argument "info".  This seems to be broken
and possibly the extra memory allocated was meant to accomodate
the ports array.  Indeed, the code removed by the commit that you
mentioned indicates this as well (although the memory was never
actually used).

Dave, I think we should talk about the maintainence of the chelsio
net/crypto drivers.  They have quite a bit of overlap and there is
simply not enough people on the crypto side to review these drivers
properly.  Would it be possible for all future changes to these
drivers to go through the net tree?
 
Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: chelsio - remove extra allocation for chtls_dev
  2020-02-13  5:47 ` Herbert Xu
@ 2020-02-14  8:10   ` Vinay Kumar Yadav
  0 siblings, 0 replies; 4+ messages in thread
From: Vinay Kumar Yadav @ 2020-02-14  8:10 UTC (permalink / raw)
  To: Herbert Xu, Stephen Kitt, David S. Miller
  Cc: Atul Gupta, linux-crypto, linux-kernel, netdev

Hi Herbert,

On 2/13/2020 11:17 AM, Herbert Xu wrote:
> On Fri, Jan 24, 2020 at 11:20:51PM +0100, Stephen Kitt wrote:
>> chtls_uld_add allocates room for info->nports net_device structs
>> following the chtls_dev struct, presumably because it was originally
>> intended that the ports array would be stored there. This is suggested
>> by the assignment which was present in initial versions and removed by
>> c4e848586cf1 ("crypto: chelsio - remove redundant assignment to
>> cdev->ports"):
>>
>> 	cdev->ports = (struct net_device **)(cdev + 1);
>>
>> This assignment was never used, being overwritten by lldi->ports
>> immediately afterwards, and I couldn't find any uses of the memory
>> allocated past the end of the struct.
>>
>> Signed-off-by: Stephen Kitt <steve@sk2.org>
> Thanks for the patch!
>
> I think the problem goes deeper though.  It appears that instead
> of allocating a ports array this function actually hangs onto the
> array from the function argument "info".  This seems to be broken
> and possibly the extra memory allocated was meant to accomodate
> the ports array.  Indeed, the code removed by the commit that you
> mentioned indicates this as well (although the memory was never
> actually used).

Yes, memory was never used. Author allocated port array but later 
realized that he can use port array allocated by lld(cxgb4) and missed 
to remove memory allocation at commit mentioned in patch. I think this 
patch will correct memory allocation.

>
> Dave, I think we should talk about the maintainence of the chelsio
> net/crypto drivers.  They have quite a bit of overlap and there is
> simply not enough people on the crypto side to review these drivers
> properly.  Would it be possible for all future changes to these
> drivers to go through the net tree?
>   
> Cheers,

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] crypto: chelsio - remove extra allocation for chtls_dev
  2020-01-24 22:20 [PATCH] crypto: chelsio - remove extra allocation for chtls_dev Stephen Kitt
  2020-02-13  5:47 ` Herbert Xu
@ 2020-02-22  1:40 ` Herbert Xu
  1 sibling, 0 replies; 4+ messages in thread
From: Herbert Xu @ 2020-02-22  1:40 UTC (permalink / raw)
  To: Stephen Kitt; +Cc: Atul Gupta, David S . Miller, linux-crypto, linux-kernel

On Fri, Jan 24, 2020 at 11:20:51PM +0100, Stephen Kitt wrote:
> chtls_uld_add allocates room for info->nports net_device structs
> following the chtls_dev struct, presumably because it was originally
> intended that the ports array would be stored there. This is suggested
> by the assignment which was present in initial versions and removed by
> c4e848586cf1 ("crypto: chelsio - remove redundant assignment to
> cdev->ports"):
> 
> 	cdev->ports = (struct net_device **)(cdev + 1);
> 
> This assignment was never used, being overwritten by lldi->ports
> immediately afterwards, and I couldn't find any uses of the memory
> allocated past the end of the struct.
> 
> Signed-off-by: Stephen Kitt <steve@sk2.org>
> ---
>  drivers/crypto/chelsio/chtls/chtls_main.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)

Patch applied.  Thanks.
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-24 22:20 [PATCH] crypto: chelsio - remove extra allocation for chtls_dev Stephen Kitt
2020-02-13  5:47 ` Herbert Xu
2020-02-14  8:10   ` Vinay Kumar Yadav
2020-02-22  1:40 ` Herbert Xu

Linux-Crypto Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-crypto/0 linux-crypto/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-crypto linux-crypto/ https://lore.kernel.org/linux-crypto \
		linux-crypto@vger.kernel.org
	public-inbox-index linux-crypto

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-crypto


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git