Module Name: src Committed By: chs Date: Tue Oct 1 17:45:25 UTC 2019
Modified Files: src/sys/net: if_media.c Log Message: in ifmedia_add(), use a wait-style memory allocation rather than not waiting and panic'ing if the allocation fails. Reported-by: syzbot+249ca42197f0b066e...@syzkaller.appspotmail.com To generate a diff of this commit: cvs rdiff -u -r1.47 -r1.48 src/sys/net/if_media.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/if_media.c diff -u src/sys/net/if_media.c:1.47 src/sys/net/if_media.c:1.48 --- src/sys/net/if_media.c:1.47 Sat Aug 10 01:04:05 2019 +++ src/sys/net/if_media.c Tue Oct 1 17:45:25 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: if_media.c,v 1.47 2019/08/10 01:04:05 mrg Exp $ */ +/* $NetBSD: if_media.c,v 1.48 2019/10/01 17:45:25 chs Exp $ */ /*- * Copyright (c) 1998 The NetBSD Foundation, Inc. @@ -76,7 +76,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.47 2019/08/10 01:04:05 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_media.c,v 1.48 2019/10/01 17:45:25 chs Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -162,14 +162,10 @@ ifmedia_add(struct ifmedia *ifm, int mwo } #endif - entry = malloc(sizeof(*entry), M_IFMEDIA, M_NOWAIT); - if (entry == NULL) - panic("ifmedia_add: can't malloc entry"); - + entry = malloc(sizeof(*entry), M_IFMEDIA, M_WAITOK); entry->ifm_media = mword; entry->ifm_data = data; entry->ifm_aux = aux; - TAILQ_INSERT_TAIL(&ifm->ifm_list, entry, ifm_list); } @@ -335,8 +331,6 @@ ifmedia_ioctl_locked(struct ifnet *ifp, int *kptr = malloc(minwords * sizeof(int), M_TEMP, M_WAITOK); - if (kptr == NULL) - return ENOMEM; /* Get the media words from the interface's list. */ ep = TAILQ_FIRST(&ifm->ifm_list); for (count = 0; ep != NULL && count < minwords;