Re: [PATCH] zram: fix idle age_sec underflow in idle_store()

From: Sergey Senozhatsky

Date: Fri Aug 28 2026 - 00:31:03 EST


On (26/08/28 13:23), Sergey Senozhatsky wrote:
> Can we instead just reject such cases? It should be an error to
> request writeback of pages that are 2y old on a system that has
> uptime of 2d.
>
> Maybe something like this:
>
> + time64_t uptime;
>
> - if (IS_ENABLED(CONFIG_ZRAM_TRACK_ENTRY_ACTIME) &&
> - !kstrtouint(buf, 0, &age_sec))
> - cutoff = ktime_sub((u32)ktime_get_boottime_seconds(),
> - age_sec);
> - else
> + if (!IS_ENABLED(CONFIG_ZRAM_TRACK_ENTRY_ACTIME) ||
> + kstrtouint(buf, 0, &age_sec))
> return -EINVAL;
> +
> + /* No slot can be older than the system uptime */
> + uptime = ktime_get_boottime_seconds();
> + if (age_sec >= uptime)
> + return -ERANGE;
> +
> + cutoff = uptime - age_sec;
> }
>
> We are probably fine doing just basic arithmetics operations on those two.
> One is u32 the other one is s64: we should be fine just doing >= and sub.
> I guess we also can use plain comparison
> cutoff > zram->table[index].attr.ac_time
> in mark_idle(). Or am I hallucinating?

That implies that cutoff becomes time64_t both in idle_store() and in
mark_idle().