Skip to content

Commit 5748eb8

Browse files
tiwaidavem330
authored andcommitted
net: ppp: Don't call bpf_prog_create() in ppp_lock
In ppp_ioctl(), bpf_prog_create() is called inside ppp_lock, which eventually calls vmalloc() and hits BUG_ON() in vmalloc.c. This patch works around the problem by moving the allocation outside the lock. The bug was revealed by the recent change in net/core/filter.c, as it allocates via vmalloc() instead of kmalloc() now. Reported-and-tested-by: Stefan Seyfried <[email protected]> Signed-off-by: Takashi Iwai <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f4a1edd commit 5748eb8

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

drivers/net/ppp/ppp_generic.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -755,23 +755,23 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
755755

756756
err = get_filter(argp, &code);
757757
if (err >= 0) {
758+
struct bpf_prog *pass_filter = NULL;
758759
struct sock_fprog_kern fprog = {
759760
.len = err,
760761
.filter = code,
761762
};
762763

763-
ppp_lock(ppp);
764-
if (ppp->pass_filter) {
765-
bpf_prog_destroy(ppp->pass_filter);
766-
ppp->pass_filter = NULL;
764+
err = 0;
765+
if (fprog.filter)
766+
err = bpf_prog_create(&pass_filter, &fprog);
767+
if (!err) {
768+
ppp_lock(ppp);
769+
if (ppp->pass_filter)
770+
bpf_prog_destroy(ppp->pass_filter);
771+
ppp->pass_filter = pass_filter;
772+
ppp_unlock(ppp);
767773
}
768-
if (fprog.filter != NULL)
769-
err = bpf_prog_create(&ppp->pass_filter,
770-
&fprog);
771-
else
772-
err = 0;
773774
kfree(code);
774-
ppp_unlock(ppp);
775775
}
776776
break;
777777
}
@@ -781,23 +781,23 @@ static long ppp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
781781

782782
err = get_filter(argp, &code);
783783
if (err >= 0) {
784+
struct bpf_prog *active_filter = NULL;
784785
struct sock_fprog_kern fprog = {
785786
.len = err,
786787
.filter = code,
787788
};
788789

789-
ppp_lock(ppp);
790-
if (ppp->active_filter) {
791-
bpf_prog_destroy(ppp->active_filter);
792-
ppp->active_filter = NULL;
790+
err = 0;
791+
if (fprog.filter)
792+
err = bpf_prog_create(&active_filter, &fprog);
793+
if (!err) {
794+
ppp_lock(ppp);
795+
if (ppp->active_filter)
796+
bpf_prog_destroy(ppp->active_filter);
797+
ppp->active_filter = active_filter;
798+
ppp_unlock(ppp);
793799
}
794-
if (fprog.filter != NULL)
795-
err = bpf_prog_create(&ppp->active_filter,
796-
&fprog);
797-
else
798-
err = 0;
799800
kfree(code);
800-
ppp_unlock(ppp);
801801
}
802802
break;
803803
}

0 commit comments

Comments
 (0)