lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Sat, 07 Nov 2015 13:02:12 -0500 (EST)
From:	David Miller <davem@...emloft.net>
To:	penguin-kernel@...ove.SAKURA.ne.jp
Cc:	edumazet@...gle.com, netdev@...r.kernel.org
Subject: Re: [PATCH] tcp: use kmalloc() than kmalloc_array().

From: Tetsuo Handa <penguin-kernel@...ove.SAKURA.ne.jp>
Date: Sun, 8 Nov 2015 00:58:50 +0900

> Tetsuo Handa wrote:
>> Commit 095dc8e0c3686d58 ("tcp: fix/cleanup inet_ehash_locks_alloc()")
>> silently changed from kmalloc() to kmalloc_array(). The latter has
>> overflow check whereas the former doesn't have.
>> 
>> If nblocks * locksz might overflow, we need to do like
>> 
>>   -  if (!hashinfo->ehash_locks && nblocks > SIZE_MAX / locksz)
>>   +  if (!hashinfo->ehash_locks && nblocks > SIZE_MAX / locksz)
> 
> Oops, I meant
> 
>    -  if (!hashinfo->ehash_locks)
>    +  if (!hashinfo->ehash_locks && nblocks > SIZE_MAX / locksz)
> 
> here.
> 
>>        hashinfo->ehash_locks = vmalloc(nblocks * locksz);
>> 
>> because kmalloc_array() detects overflow and returns NULL.
>> But if nblocks * locksz is guaranteed not to overflow, there is
>> no need to use kmalloc_array().
>> 
>> Since I assume it won't overflow, use kmalloc() than kmalloc_array().
> 
> I don't know about possible value range.
> Please confirm that it can't overflow.

Whether it can overflow or not, I don't like your change at all.

If kmalloc_array() provides overflow protection, we want to keep using
it, rather than reverting back to not checking for overflow.

kmalloc_array() can fail for us at this stage for two reasons, either:

1) overflow

2) allocation size exceeds kmalloc() maximum alloc size

so if you want to be completely perfect about all of this you need
to add code to distinguish between these two cases as you suggest
above.
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Powered by blists - more mailing lists