Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp464486yba; Wed, 15 May 2019 04:34:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqxJFqlVrw3LAVbynvXKSLgPYpSpwziqRrOq5qHJhNnIxA/tkM1Advt593gticBQgnFduUAX X-Received: by 2002:a62:585:: with SMTP id 127mr26787410pff.231.1557920093349; Wed, 15 May 2019 04:34:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557920093; cv=none; d=google.com; s=arc-20160816; b=QDAxTmjeKos0ufnIOmIZHh9wmZXZEq9gDhC/72f8WfYHYUC0X+P0+664zTiG0NdMj1 ZQxwD/P03bNez7bXQzR+cL99CUWAEfsRXelB1jPeyXiDmZXr0IWRbuzTgI632DolCkZH sYRFVX229JQbrQGuEJiP+Oa0K/xGc7+TqCf+iI7IejXyl3EB2LXAZfTyAYew8TyMYhca Upm7uookM+n03lGEn9llfCQSAwu0IZlVMkyDJBjtXKQh+6B49OAUXGECI7W0mmvfXBoh qIbGQuXwAgmCUHyKLqkOils/ecEWGx+14xjIP5flEpZF1pdMfTRJYj3xaldouFOT5/+B hk1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=J4Gy3PET9fyN3/QnVMDopgBxvXmxuWT4eXZRGEQJHBk=; b=nclmB74w1ZpWzZ01qPFVTkRiBONEhcFfP5wRkACZ7mDfeniXQdbg83I+ALkFde3pbH DEjyUB55SyaCJRmCMJ2dOz72Qg0J2bQfSLbe6wQrrkkDjG6DbEGe8U6V4l3SPRxzSoBv O1sJP+FO0B52vaVaM1eVuC6Tdoe5Q282gu8sgiVld4DX+rfiDc/f1b6fBH6e51Q3s77A jG0MM9OfkQxEYYGWa06guit50qXpl3YU9FTVdUFk1Byzt7Aq/3xkjDmVLY+AYRREMCeC ZzJR46lF64taC9n6Ke6Ran/ndFeWCdriSKSe7Q1Tya6YUguuZsHGm/5zw9r6ntSemMs2 F2Rg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UWblLjL1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61si1284676plq.398.2019.05.15.04.34.38; Wed, 15 May 2019 04:34:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UWblLjL1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732940AbfEOLby (ORCPT + 99 others); Wed, 15 May 2019 07:31:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:43638 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732657AbfEOLbv (ORCPT ); Wed, 15 May 2019 07:31:51 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CBDAA20843; Wed, 15 May 2019 11:31:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1557919910; bh=ppDG6mfQthnYQOTjGBktELqcYo9OvuBX2RDhmW4fnsM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UWblLjL1cmZT6S/t29uWO5SAj2iwd72mIpNqNQPS/fluxhqAA1YMmsus3FHT3g+Es HUcHszjZKNnL0RXv800ivmQki4WN44bP5SdO2VUT/etwpdAXq/ur1lGVxK7WKlAc7I g+qNjFoZtafw3lta0CcVoZykyekpcStrJGlPfj74= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Dumazet , syzbot , Petar Penkov , Stanislav Fomichev , "David S. Miller" Subject: [PATCH 5.0 126/137] flow_dissector: disable preemption around BPF calls Date: Wed, 15 May 2019 12:56:47 +0200 Message-Id: <20190515090703.057029785@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190515090651.633556783@linuxfoundation.org> References: <20190515090651.633556783@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Dumazet [ Upstream commit b1c17a9a353878602fd5bfe9103e4afe5e9a3f96 ] Various things in eBPF really require us to disable preemption before running an eBPF program. syzbot reported : BUG: assuming atomic context at net/core/flow_dissector.c:737 in_atomic(): 0, irqs_disabled(): 0, pid: 24710, name: syz-executor.3 2 locks held by syz-executor.3/24710: #0: 00000000e81a4bf1 (&tfile->napi_mutex){+.+.}, at: tun_get_user+0x168e/0x3ff0 drivers/net/tun.c:1850 #1: 00000000254afebd (rcu_read_lock){....}, at: __skb_flow_dissect+0x1e1/0x4bb0 net/core/flow_dissector.c:822 CPU: 1 PID: 24710 Comm: syz-executor.3 Not tainted 5.1.0+ #6 Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 01/01/2011 Call Trace: __dump_stack lib/dump_stack.c:77 [inline] dump_stack+0x172/0x1f0 lib/dump_stack.c:113 __cant_sleep kernel/sched/core.c:6165 [inline] __cant_sleep.cold+0xa3/0xbb kernel/sched/core.c:6142 bpf_flow_dissect+0xfe/0x390 net/core/flow_dissector.c:737 __skb_flow_dissect+0x362/0x4bb0 net/core/flow_dissector.c:853 skb_flow_dissect_flow_keys_basic include/linux/skbuff.h:1322 [inline] skb_probe_transport_header include/linux/skbuff.h:2500 [inline] skb_probe_transport_header include/linux/skbuff.h:2493 [inline] tun_get_user+0x2cfe/0x3ff0 drivers/net/tun.c:1940 tun_chr_write_iter+0xbd/0x156 drivers/net/tun.c:2037 call_write_iter include/linux/fs.h:1872 [inline] do_iter_readv_writev+0x5fd/0x900 fs/read_write.c:693 do_iter_write fs/read_write.c:970 [inline] do_iter_write+0x184/0x610 fs/read_write.c:951 vfs_writev+0x1b3/0x2f0 fs/read_write.c:1015 do_writev+0x15b/0x330 fs/read_write.c:1058 __do_sys_writev fs/read_write.c:1131 [inline] __se_sys_writev fs/read_write.c:1128 [inline] __x64_sys_writev+0x75/0xb0 fs/read_write.c:1128 do_syscall_64+0x103/0x670 arch/x86/entry/common.c:298 entry_SYSCALL_64_after_hwframe+0x49/0xbe Fixes: d58e468b1112 ("flow_dissector: implements flow dissector BPF hook") Signed-off-by: Eric Dumazet Reported-by: syzbot Cc: Petar Penkov Cc: Stanislav Fomichev Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/flow_dissector.c | 3 +++ 1 file changed, 3 insertions(+) --- a/net/core/flow_dissector.c +++ b/net/core/flow_dissector.c @@ -786,7 +786,10 @@ bool __skb_flow_dissect(const struct sk_ flow_keys.thoff = nhoff; bpf_compute_data_pointers((struct sk_buff *)skb); + + preempt_disable(); result = BPF_PROG_RUN(attached, skb); + preempt_enable(); /* Restore state */ memcpy(cb, &cb_saved, sizeof(cb_saved));