mailing list of musl libc
 help / color / Atom feed
* [musl] [PATCH] fix coredump when sched_rr_get_interval parameter ts is NULL
       [not found] <20200508143931.5165-1-zhuyan34@huawei.com>
@ 2020-05-08 14:46 ` zhuyan (M)
  2020-05-08 15:47   ` Markus Wichmann
  0 siblings, 1 reply; 3+ messages in thread
From: zhuyan (M) @ 2020-05-08 14:46 UTC (permalink / raw)
  To: musl; +Cc: Zengweilin, liucheng (G), zhuyan (M)

In function sched_rr_get_interval, there is a risk of null pointer reference. On line 12, when ts is NULL, dereferencing the null pointer will cause the program coredump.

Therefore, it must ensure that ts is not empty before use.

Signed-off-by: Yan Zhu <zhuyan34@huawei.com>
---
 src/sched/sched_rr_get_interval.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/sched/sched_rr_get_interval.c b/src/sched/sched_rr_get_interval.c
index 33a3d1a..3577291 100644
--- a/src/sched/sched_rr_get_interval.c
+++ b/src/sched/sched_rr_get_interval.c
@@ -9,6 +9,8 @@ int sched_rr_get_interval(pid_t pid, struct timespec *ts)
 		long ts32[2];
 		int r = __syscall(SYS_sched_rr_get_interval, pid, ts32);
 		if (!r) {
+			if (ts == NULL)
+				return -1;
 			ts->tv_sec = ts32[0];
 			ts->tv_nsec = ts32[1];
 		}
--
2.24.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [musl] [PATCH] fix coredump when sched_rr_get_interval parameter ts is NULL
  2020-05-08 14:46 ` [musl] [PATCH] fix coredump when sched_rr_get_interval parameter ts is NULL zhuyan (M)
@ 2020-05-08 15:47   ` Markus Wichmann
  2020-05-08 18:45     ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Markus Wichmann @ 2020-05-08 15:47 UTC (permalink / raw)
  To: musl

On Fri, May 08, 2020 at 02:46:56PM +0000, zhuyan (M) wrote:
> In function sched_rr_get_interval, there is a risk of null pointer reference. On line 12, when ts is NULL, dereferencing the null pointer will cause the program coredump.
>
> Therefore, it must ensure that ts is not empty before use.
>

Is calling this function with a NULL pointer sensible? The manpage
certainly doesn't say so. Usually policy in musl is to not fix
application bugs, but to dereference pointers without NULL pointer check
unless there is an explicit requirement in the relevant standards that a
NULL pointer be accepted.

Ciao,
Markus

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [musl] [PATCH] fix coredump when sched_rr_get_interval parameter ts is NULL
  2020-05-08 15:47   ` Markus Wichmann
@ 2020-05-08 18:45     ` Rich Felker
  0 siblings, 0 replies; 3+ messages in thread
From: Rich Felker @ 2020-05-08 18:45 UTC (permalink / raw)
  To: Markus Wichmann; +Cc: musl, zhuyan (M)

On Fri, May 08, 2020 at 05:47:37PM +0200, Markus Wichmann wrote:
> On Fri, May 08, 2020 at 02:46:56PM +0000, zhuyan (M) wrote:
> > In function sched_rr_get_interval, there is a risk of null pointer
> > reference. On line 12, when ts is NULL, dereferencing the null
> > pointer will cause the program coredump.
> >
> > Therefore, it must ensure that ts is not empty before use.
> >
> 
> Is calling this function with a NULL pointer sensible? The manpage
> certainly doesn't say so. Usually policy in musl is to not fix
> application bugs, but to dereference pointers without NULL pointer check
> unless there is an explicit requirement in the relevant standards that a
> NULL pointer be accepted.

Indeed, sched_rr_get_interval has no contract to accept a null
pointer, and doesn't even have a plausible reason to want to call it
with one (the only output is in the pointed-to memory).

Rich

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20200508143931.5165-1-zhuyan34@huawei.com>
2020-05-08 14:46 ` [musl] [PATCH] fix coredump when sched_rr_get_interval parameter ts is NULL zhuyan (M)
2020-05-08 15:47   ` Markus Wichmann
2020-05-08 18:45     ` Rich Felker

mailing list of musl libc

Archives are clonable: git clone --mirror http://inbox.vuxu.org/musl

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.musl


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git