zram: explicitly limit prio_max for static analyzers

Message ID 20221114021420.4060601-1-senozhatsky@chromium.org
State New
Headers
Series zram: explicitly limit prio_max for static analyzers |

Commit Message

Sergey Senozhatsky Nov. 14, 2022, 2:14 a.m. UTC
  Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
---
 drivers/block/zram/zram_drv.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Andrew Morton Nov. 15, 2022, 12:41 a.m. UTC | #1
On Mon, 14 Nov 2022 11:14:20 +0900 Sergey Senozhatsky <senozhatsky@chromium.org> wrote:

> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
> ---
>  drivers/block/zram/zram_drv.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> index 9d33801e8ba8..e67a124f2e88 100644
> --- a/drivers/block/zram/zram_drv.c
> +++ b/drivers/block/zram/zram_drv.c
> @@ -1706,6 +1706,7 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page,
>  	 * Iterate the secondary comp algorithms list (in order of priority)
>  	 * and try to recompress the page.
>  	 */
> +	prio_max = min(prio_max, ZRAM_MAX_COMPS);
>  	for (; prio < prio_max; prio++) {
>  		if (!zram->comps[prio])
>  			continue;

I'll queue this as a fix to "zram: introduce recompress sysfs knob".

What's it do?  A little changelog would be nice, or at least a link to
the coverity report?
  
Sergey Senozhatsky Nov. 15, 2022, 12:47 a.m. UTC | #2
On (22/11/14 16:41), Andrew Morton wrote:
> >  drivers/block/zram/zram_drv.c | 1 +
> >  1 file changed, 1 insertion(+)
> > 
> > diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
> > index 9d33801e8ba8..e67a124f2e88 100644
> > --- a/drivers/block/zram/zram_drv.c
> > +++ b/drivers/block/zram/zram_drv.c
> > @@ -1706,6 +1706,7 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page,
> >  	 * Iterate the secondary comp algorithms list (in order of priority)
> >  	 * and try to recompress the page.
> >  	 */
> > +	prio_max = min(prio_max, ZRAM_MAX_COMPS);
> >  	for (; prio < prio_max; prio++) {
> >  		if (!zram->comps[prio])
> >  			continue;
> 
> I'll queue this as a fix to "zram: introduce recompress sysfs knob".
> 
> What's it do?  A little changelog would be nice, or at least a link to
> the coverity report?

It doesn't do much, coverity (static analyzer?) got confused by
the code, so this simply is supposed to help coverity figure out
that we never do an out of bounds access in comps[] array:
https://lore.kernel.org/lkml/202211100847.388C61B3@keescook/
  

Patch

diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 9d33801e8ba8..e67a124f2e88 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -1706,6 +1706,7 @@  static int zram_recompress(struct zram *zram, u32 index, struct page *page,
 	 * Iterate the secondary comp algorithms list (in order of priority)
 	 * and try to recompress the page.
 	 */
+	prio_max = min(prio_max, ZRAM_MAX_COMPS);
 	for (; prio < prio_max; prio++) {
 		if (!zram->comps[prio])
 			continue;