Skip to content

Commit

Permalink
fix free_all_endpoints() to not try calling free_pipe() when no endpo…
Browse files Browse the repository at this point in the history
…ints

are allocated; this can happen during config_detach() after attach fails

Reported-by: syzbot+6e8a4c978358ecead03e@syzkaller.appspotmail.com
Reported-by: syzbot+b25ba25b57561144ac6e@syzkaller.appspotmail.com
  • Loading branch information
jdolecek-zz committed Jan 20, 2021
1 parent cf6aa6e commit 8c601f6
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions sys/dev/usb/umidi.c
@@ -1,4 +1,4 @@
/* $NetBSD: umidi.c,v 1.82 2020/01/02 08:08:30 maxv Exp $ */
/* $NetBSD: umidi.c,v 1.83 2021/01/20 22:46:33 jdolecek Exp $ */

/*
* Copyright (c) 2001, 2012, 2014 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -32,7 +32,7 @@
*/

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.82 2020/01/02 08:08:30 maxv Exp $");
__KERNEL_RCSID(0, "$NetBSD: umidi.c,v 1.83 2021/01/20 22:46:33 jdolecek Exp $");

#ifdef _KERNEL_OPT
#include "opt_usb.h"
Expand Down Expand Up @@ -756,10 +756,14 @@ free_all_endpoints(struct umidi_softc *sc)
{
int i;

if (sc->sc_endpoints == NULL) {
/* nothing to free */
return;
}

for (i=0; i<sc->sc_in_num_endpoints+sc->sc_out_num_endpoints; i++)
free_pipe(&sc->sc_endpoints[i]);
if (sc->sc_endpoints != NULL)
kmem_free(sc->sc_endpoints, sc->sc_endpoints_len);
kmem_free(sc->sc_endpoints, sc->sc_endpoints_len);
sc->sc_endpoints = sc->sc_out_ep = sc->sc_in_ep = NULL;
}

Expand Down

0 comments on commit 8c601f6

Please sign in to comment.