From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E3EEC5B578 for ; Mon, 1 Jul 2019 23:42:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 23AC12146F for ; Mon, 1 Jul 2019 23:42:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=appneta.com header.i=@appneta.com header.b="RbaR1CGo" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726977AbfGAXms (ORCPT ); Mon, 1 Jul 2019 19:42:48 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:41640 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726347AbfGAXmr (ORCPT ); Mon, 1 Jul 2019 19:42:47 -0400 Received: by mail-pl1-f194.google.com with SMTP id m7so8084421pls.8 for ; Mon, 01 Jul 2019 16:42:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=appneta.com; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/1gFnr0TRR2O3FrkKYtrpBMih30lPMQm08/0jo878LU=; b=RbaR1CGorAnHwg8FKM9bcyODEuwoYJP/M0w052lY2ZCB+nEFaFR9tGs0jADg2uSoJJ 1HDAEnAbsPVf5ue4PWcnvhegWZWUmmaTGqru+XueNMNBC7F3h/HO0ajjFRsLL+/cxNpJ AJKYhJuiSaevSWnZsr0ivrbQNZqyRAKMD0plo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=/1gFnr0TRR2O3FrkKYtrpBMih30lPMQm08/0jo878LU=; b=uecmMdx/ogL2/6d/k1WZV84cCws49JJNTSiCc9S3v0I6CM0WULzTfqKOnhMbYjRr2c S7Vhhskh3Q1O8V9ZuE/GOtXQr74gvFXpt/EdzXBCia60vxDSwg9G9JkA3tA9VO9rp9vo wZMBb2OhtTLl9FHtwqzF4G9bi+HAuzloWqYo6hCXh24GkcP01TxTDf/tTRepuUxlXpA0 cgFMEvWBQsmnvJ4ORj9lRBg7qvmdM3fNJvZjgp7u36+WLfNnlNTZ2Z0e4e81vlf0bGLn sFNEwPcnqYRDjHBW9suNElhuyQOcNnWlSULoYsb2UmGCQnykkVU0B/wLIicPmh85RH+R jg8g== X-Gm-Message-State: APjAAAUms5NTUMdHIUkd41bdUUzcoyATJqeei1rkUd1ifBC7/39BX+vy dcFLOyPCiz2vhW4M4JQ/kz7F X-Google-Smtp-Source: APXvYqyNSKz1gT/iRKaIQQquDe8Q0lrmObw5tu5nQIPPoUqKGuIs+8sMxeLq0U0tzq6Zz5/11Fu7/A== X-Received: by 2002:a17:902:b093:: with SMTP id p19mr30781404plr.141.1562024567104; Mon, 01 Jul 2019 16:42:47 -0700 (PDT) Received: from debian9-jae.jaalam.net (64-46-6-129.dyn.novuscom.net. [64.46.6.129]) by smtp.gmail.com with ESMTPSA id b36sm609336pjc.16.2019.07.01.16.42.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Jul 2019 16:42:46 -0700 (PDT) From: Josh Elsasser To: stable@vger.kernel.org Cc: Josh Elsasser , gregkh@linuxfoundation.org, netdev@vger.kernel.org, "David S. Miller" , Eric Dumazet , Matteo Croce Subject: [PATCH RESEND 4.9.y] net: check before dereferencing netdev_ops during busy poll Date: Mon, 1 Jul 2019 16:41:43 -0700 Message-Id: <20190701234143.72631-1-jelsasser@appneta.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org init_dummy_netdev() leaves its netdev_ops pointer zeroed. This leads to a NULL pointer dereference when sk_busy_loop fires against an iwlwifi wireless adapter and checks napi->dev->netdev_ops->ndo_busy_poll. Avoid this by ensuring napi->dev->netdev_ops is valid before following the pointer, avoiding the following panic when busy polling on a dummy netdev: BUG: unable to handle kernel NULL pointer dereference at 00000000000000c8 IP: [] sk_busy_loop+0x92/0x2f0 Call Trace: [] ? uart_write_room+0x74/0xf0 [] sock_poll+0x99/0xa0 [] do_sys_poll+0x2e2/0x520 [] ? get_page_from_freelist+0x3bc/0xa30 [] ? update_curr+0x62/0x140 [] ? __slab_free+0xa1/0x2a0 [] ? __slab_free+0xa1/0x2a0 [] ? skb_free_head+0x21/0x30 [] ? poll_initwait+0x50/0x50 [] ? kmem_cache_free+0x1c6/0x1e0 [] ? uart_write+0x124/0x1d0 [] ? remove_wait_queue+0x4d/0x60 [] ? __wake_up+0x44/0x50 [] ? tty_write_unlock+0x31/0x40 [] ? tty_ldisc_deref+0x16/0x20 [] ? tty_write+0x1e0/0x2f0 [] ? process_echoes+0x80/0x80 [] ? __vfs_write+0x2b/0x130 [] ? vfs_write+0x15a/0x1a0 [] SyS_poll+0x75/0x100 [] entry_SYSCALL_64_fastpath+0x24/0xcf Commit 79e7fff47b7b ("net: remove support for per driver ndo_busy_poll()") indirectly fixed this upstream in linux-4.11 by removing the offending pointer usage. No other users of napi->dev touch its netdev_ops. Fixes: ce6aea93f751 ("net: network drivers no longer need to implement ndo_busy_poll()") # 4.9.y Signed-off-by: Josh Elsasser Reviewed-by: Eric Dumazet Tested-by: Matteo Croce --- No changes since V2[1], resent as per discussiond on -stable[2]. I hope this is the correct way to send net fixes for older LTS releases, I'm going off of the latest netdev FAQ: For earlier stable releases, each stable branch maintainer is supposed to take care of them. If you find any patch is missing from an earlier stable branch, please notify stable@vger.kernel.org with either a commit ID or a formal patch backported, and CC Dave and other relevant networking developers. [1]: https://patchwork.ozlabs.org/patch/884986/ [2]: https://lore.kernel.org/stable/CAGnkfhx3ykbEsW+=FtpMFWU=_Vnie7RpPYWpWqa1S1HPMXj9kw@mail.gmail.com/ net/core/dev.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/core/dev.c b/net/core/dev.c index 4e10bae5e3da..f693afe608d7 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -5083,7 +5083,10 @@ bool sk_busy_loop(struct sock *sk, int nonblock) goto out; /* Note: ndo_busy_poll method is optional in linux-4.5 */ - busy_poll = napi->dev->netdev_ops->ndo_busy_poll; + if (napi->dev->netdev_ops) + busy_poll = napi->dev->netdev_ops->ndo_busy_poll; + else + busy_poll = NULL; do { rc = 0; -- 2.20.1