Re: [PATCH] printk: fix integer overflow in setup_log_buf()

From: Sergey Senozhatsky
Date: Wed Oct 10 2018 - 07:31:35 EST

On (10/10/18 19:38), Sergey Senozhatsky wrote:
> The way we calculate free logbuf free space percentage
> overflows signed integer:
> int free;
> free = __LOG_BUF_LEN - log_next_idx;
> pr_info("early log buf free: %u(%u%%)\n",
> free, (free * 100) / __LOG_BUF_LEN);
> We support LOG_BUF_LEN of up to 2G, since setup_log_buf() is called
> during early init logbuf is mostly empty, so
> __LOG_BUF_LEN - log_next_idx
> is close to 2G. When we multiply it by 100, we overflow signed
> integer value range.

I'm really sorry. The commit message got totally messed up here.
What I meant was 1<<25. I used 2G as a boot param for testing to
set up a proper new_log_buf_len value. And somehow got confused,
I was in a hurry. I'll send a follow up with fixed commit message.