* [PATCH v1 1/1] lib/vsprintf: Check pointer before dereferencing in time_and_date()
@ 2025-11-10 13:21 Andy Shevchenko
2025-11-10 14:44 ` Petr Mladek
2025-11-12 10:59 ` Petr Mladek
0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2025-11-10 13:21 UTC (permalink / raw)
To: linux-kernel
Cc: Petr Mladek, Steven Rostedt, Andy Shevchenko, Rasmus Villemoes,
Sergey Senozhatsky, Andrew Morton
The pointer may be invalid when gets to the printf(). In particular
the time_and_date() dereferencing it in some cases without checking.
Move the check from rtc_str() to time_and_date() to cover all cases.
Fixes: 7daac5b2fdf8 ("lib/vsprintf: Print time64_t in human readable format")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
lib/vsprintf.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index e49f350ee549..3f99834fd788 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -1928,9 +1928,6 @@ char *rtc_str(char *buf, char *end, const struct rtc_time *tm,
bool found = true;
int count = 2;
- if (check_pointer(&buf, end, tm, spec))
- return buf;
-
switch (fmt[count]) {
case 'd':
have_t = false;
@@ -1996,6 +1993,9 @@ static noinline_for_stack
char *time_and_date(char *buf, char *end, void *ptr, struct printf_spec spec,
const char *fmt)
{
+ if (check_pointer(&buf, end, ptr, spec))
+ return buf;
+
switch (fmt[1]) {
case 'R':
return rtc_str(buf, end, (const struct rtc_time *)ptr, spec, fmt);
--
2.50.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v1 1/1] lib/vsprintf: Check pointer before dereferencing in time_and_date()
2025-11-10 13:21 [PATCH v1 1/1] lib/vsprintf: Check pointer before dereferencing in time_and_date() Andy Shevchenko
@ 2025-11-10 14:44 ` Petr Mladek
2025-11-12 10:59 ` Petr Mladek
1 sibling, 0 replies; 3+ messages in thread
From: Petr Mladek @ 2025-11-10 14:44 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-kernel, Steven Rostedt, Rasmus Villemoes,
Sergey Senozhatsky, Andrew Morton
On Mon 2025-11-10 14:21:18, Andy Shevchenko wrote:
> The pointer may be invalid when gets to the printf(). In particular
> the time_and_date() dereferencing it in some cases without checking.
>
> Move the check from rtc_str() to time_and_date() to cover all cases.
>
> Fixes: 7daac5b2fdf8 ("lib/vsprintf: Print time64_t in human readable format")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Great catch!
Reviewed-by: Petr Mladek <pmladek@suse.com>
Best Regards,
Petr
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v1 1/1] lib/vsprintf: Check pointer before dereferencing in time_and_date()
2025-11-10 13:21 [PATCH v1 1/1] lib/vsprintf: Check pointer before dereferencing in time_and_date() Andy Shevchenko
2025-11-10 14:44 ` Petr Mladek
@ 2025-11-12 10:59 ` Petr Mladek
1 sibling, 0 replies; 3+ messages in thread
From: Petr Mladek @ 2025-11-12 10:59 UTC (permalink / raw)
To: Andy Shevchenko
Cc: linux-kernel, Steven Rostedt, Rasmus Villemoes,
Sergey Senozhatsky, Andrew Morton
On Mon 2025-11-10 14:21:18, Andy Shevchenko wrote:
> The pointer may be invalid when gets to the printf(). In particular
> the time_and_date() dereferencing it in some cases without checking.
>
> Move the check from rtc_str() to time_and_date() to cover all cases.
>
> Fixes: 7daac5b2fdf8 ("lib/vsprintf: Print time64_t in human readable format")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
JFYI, the patch has been comitted into printk/linux.git,
branch for-6.19.
Best Regards,
Petr
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-11-12 10:59 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-10 13:21 [PATCH v1 1/1] lib/vsprintf: Check pointer before dereferencing in time_and_date() Andy Shevchenko
2025-11-10 14:44 ` Petr Mladek
2025-11-12 10:59 ` Petr Mladek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox