Skip to contentSkip to conversation

general protection fault in sctp_sched_prio_sched

DISCUSSION Marcelo Ricardo Leitner 1 participant 1 message Jun 18, 2019 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

Marcelo Ricardo Leitner

author maintainer
#1 lore raw
In reply to a message not in the archive

Hi,

Quoted 102 lines · Hillf Danton

Hello Marcelo

Quoted 33 lines · On Mon, 17 Jun 2019 22:43:38 +0800 Marcelo Ricardo Leitner wrote:
Quoted 32 lines · Marcelo Ricardo Leitner

Hi,

Quoted 8 lines · Hillf Danton

Hello Syzbot

Quoted 4 lines · On Sat, 15 Jun 2019 16:36:06 -0700 (PDT) syzbot wrote:

Hello,

syzbot found the following crash on:

...

Quoted 20 lines

Check prio_head and bail out if it is not valid.

Thanks
Hillf
----->8---
---
net/sctp/stream_sched_prio.c | 2 ++

1 file changed, 2 insertions(+)
net/sctp/stream_sched_prio.c +2 -0
index 2245083..db25a43 100644
@@ -135,6 +135,8 @@ static void sctp_sched_prio_sched(struct sctp_stream *stream,
 	struct sctp_stream_priorities *prio, *prio_head;
 
 	prio_head = soute->prio_head;
+	if (!prio_head)
+		return;
 
Quoted 7 lines
Quoted 7 lines

net/sctp/stream_sched_prio.c static void sctp_sched_prio_sched(struct sctp_stream *stream,

Quoted 3 lines
net/sctp/stream_sched_prio.c +0 -1
 	/* Nothing to do if already scheduled */
 	if (!list_empty(&soute->prio_list))
--

Thanks but this is not a good fix for this. It will cause the stream to never be scheduled.

Thanks very much for the light you are casting.

Quoted 12 lines
Quoted 12 lines

The problem happens because of the fault injection that happened a bit before the crash, in here:

int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid)

{
        struct sctp_stream_out_ext *soute;

        soute = kzalloc(sizeof(*soute), GFP_KERNEL);
        if (!soute)
                return -ENOMEM;
        SCTP_SO(stream, sid)->ext = soute;  <---- [A]
Quoted 4 lines
Quoted 4 lines
        return sctp_sched_init_sid(stream, sid, GFP_KERNEL);
                      ^^^^^^^^^^^^---- [B] failed
}

Eagle eye.

Quoted 13 lines
Quoted 13 lines

This causes the 1st sendmsg to bail out with the error. When the 2nd one gets in, it will:

sctp_sendmsg_to_asoc()
{
...

        if (unlikely(!SCTP_SO(&asoc->stream, sinfo->sinfo_stream)->ext)) {
                                                                 ^^^^^--- [C]
                err = sctp_stream_init_ext(&asoc->stream, sinfo->sinfo_stream);
                if (err)
                        goto err;
        }
Quoted 3 lines
Quoted 3 lines

[A] leaves ext initialized, despite the failed in [B]. Then in [C], it will not try to initialize again.

Fairly concise.

Quoted 20 lines
Quoted 2 lines

We need to either uninitialize ->ext as error handling for [B], or improve the check on [C].

The former one, please. This should be enough (untested):

net/sctp/stream.c +1 -0
index 93ed07877337..25946604af85 100644
@@ -153,13 +153,20 @@ int sctp_stream_init(struct sctp_stream *stream, __u1> > 6 outcnt, __u16 incnt,
 int sctp_stream_init_ext(struct sctp_stream *stream, __u16 sid)
 {
 	struct sctp_stream_out_ext *soute;
+	int ret;
 
 	soute = kzalloc(sizeof(*soute), GFP_KERNEL);
 	if (!soute)
 		return -ENOMEM;
 	SCTP_SO(stream, sid)->ext = soute;
 
Quoted 5 lines

net/sctp/stream.c int sctp_stream_init(struct sctp_stream *stream, __u1> > 6 outcnt, __u16 incnt, · line 166

Quoted 5 lines
net/sctp/stream.c +4 -1
-	return sctp_sched_init_sid(stream, sid, GFP_KERNEL);
+	ret = sctp_sched_init_sid(stream, sid, GFP_KERNEL);
+	if (ret) {
+		kfree(SCTP_SO(stream, sid)->ext);
+		SCTP_SO(stream, sid)->ext = NULL;

[D]

Quoted 7 lines

net/sctp/stream.c int sctp_stream_init(struct sctp_stream *stream, __u1> > 6 outcnt, __u16 incnt, · line 171

Quoted 5 lines
net/sctp/stream.c +3 -0
+	}
+
+	return ret;
 }
 

Definitely nice.

Quoted 7 lines

net/sctp/stream.c int sctp_stream_init(struct sctp_stream *stream, __u1> > 6 outcnt, __u16 incnt, · line 172

Quoted 2 lines
net/sctp/stream.c +0 -0
 void sctp_stream_free(struct sctp_stream *stream)

Hmmm, ->ext will be valid, provided it is loaded with a valid slab in sctp_stream_init_ext() regardless of whether sid is successfully initialised, until it is released, for instance, in sctp_stream_free(), and based on that assumption, it looks hardly likely that ->ext has a chance to create a gfp in sctp_sched_prio_sched().

I'm not sure I follow you. Anyway, with the patch above, after calling sctp_stream_init_ext() ->ext will be either completely valid, or it will not be present at all as it is seting ->ext to NULL if sid initialization ended up failing.

Marcelo