Skip to content

Commit b53cf28

Browse files
mugitya03jinyaoguo
authored andcommitted
network: fix a potential divide-by-zero (#37705)
In function `tc_init`, hz is parsed from the content of file `"/proc/net/psched"` and can be 0. In function `hierarchy_token_bucket_class_verify`, hz is directly used as a divisor in `htb->buffer = htb->rate / hz + htb->mtu;` without any check. This adds a check on hz before using it as a divisor. Co-authored-by: jinyaoguo <[email protected]> (cherry picked from commit 1a596054a0f937bfc244580f07510759a0e45657) (cherry picked from commit e2c9fdd5c0f84eb234e122fe8fce9c4d949882cd) (cherry picked from commit 64206ad1372a7df4c96c1fd8cd363a6032eaeadf)
1 parent d1bf709 commit b53cf28

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/network/tc/htb.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,8 @@ static int hierarchy_token_bucket_class_verify(TClass *tclass) {
470470
if (r < 0)
471471
return log_error_errno(r, "Failed to read /proc/net/psched: %m");
472472

473+
/* Kernel would never hand us 0 Hz. */
474+
assert(hz > 0);
473475
if (htb->buffer == 0)
474476
htb->buffer = htb->rate / hz + htb->mtu;
475477
if (htb->ceil_buffer == 0)

0 commit comments

Comments
 (0)