Skip to content

Commit 74da779

Browse files
Dan Carpenterkuba-moo
authored andcommitted
net/tcp_sigpool: Fix some off by one bugs
The "cpool_populated" variable is the number of elements in the cpool[] array that have been populated. It is incremented in tcp_sigpool_alloc_ahash() every time we populate a new element. Unpopulated elements are NULL but if we have populated every element then this code will read one element beyond the end of the array. Fixes: 8c73b26 ("net/tcp: Prepare tcp_md5sig_pool for TCP-AO") Signed-off-by: Dan Carpenter <[email protected]> Reviewed-by: Dmitry Safonov <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 19b3f72 commit 74da779

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

net/ipv4/tcp_sigpool.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ static void cpool_schedule_cleanup(struct kref *kref)
231231
*/
232232
void tcp_sigpool_release(unsigned int id)
233233
{
234-
if (WARN_ON_ONCE(id > cpool_populated || !cpool[id].alg))
234+
if (WARN_ON_ONCE(id >= cpool_populated || !cpool[id].alg))
235235
return;
236236

237237
/* slow-path */
@@ -245,7 +245,7 @@ EXPORT_SYMBOL_GPL(tcp_sigpool_release);
245245
*/
246246
void tcp_sigpool_get(unsigned int id)
247247
{
248-
if (WARN_ON_ONCE(id > cpool_populated || !cpool[id].alg))
248+
if (WARN_ON_ONCE(id >= cpool_populated || !cpool[id].alg))
249249
return;
250250
kref_get(&cpool[id].kref);
251251
}
@@ -256,7 +256,7 @@ int tcp_sigpool_start(unsigned int id, struct tcp_sigpool *c) __cond_acquires(RC
256256
struct crypto_ahash *hash;
257257

258258
rcu_read_lock_bh();
259-
if (WARN_ON_ONCE(id > cpool_populated || !cpool[id].alg)) {
259+
if (WARN_ON_ONCE(id >= cpool_populated || !cpool[id].alg)) {
260260
rcu_read_unlock_bh();
261261
return -EINVAL;
262262
}
@@ -301,7 +301,7 @@ EXPORT_SYMBOL_GPL(tcp_sigpool_end);
301301
*/
302302
size_t tcp_sigpool_algo(unsigned int id, char *buf, size_t buf_len)
303303
{
304-
if (WARN_ON_ONCE(id > cpool_populated || !cpool[id].alg))
304+
if (WARN_ON_ONCE(id >= cpool_populated || !cpool[id].alg))
305305
return -EINVAL;
306306

307307
return strscpy(buf, cpool[id].alg, buf_len);

0 commit comments

Comments
 (0)