From patchwork Thu May 18 07:50:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: linzhang X-Patchwork-Id: 9732849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4EC62600CC for ; Thu, 18 May 2017 07:50:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2EA8B287BD for ; Thu, 18 May 2017 07:50:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22EF328812; Thu, 18 May 2017 07:50:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCF9E28806 for ; Thu, 18 May 2017 07:50:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754874AbdERHuP (ORCPT ); Thu, 18 May 2017 03:50:15 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:36054 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754670AbdERHuO (ORCPT ); Thu, 18 May 2017 03:50:14 -0400 Received: by mail-pg0-f67.google.com with SMTP id h64so4998795pge.3; Thu, 18 May 2017 00:50:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=gRLn8qJuTlxCybT0NvPOQts7Km/pC8Xm3jqjjCzfF5Y=; b=DUfGTCw+eWiNjWnYQBRbcNini9tO2IUMOkabtiyz8edu1YDs0jTqtZVQMZwL4klZQC dmjUBVhrAuYQnEfAMMamZcjikjOt0Cy2U8EZLWryc8l3PlCnFJ+wjcp1l5Jwr+nd9cEe DubEQ8OdMWPonN/vV2jpNsPp+r1c5tE04KhJ+8NtoGKZS4n+HDdTtjken8gCEdGgXDkI Kc+TtQVNJ5MAcHwrNZjwH6itfvNJbYSCDoSlO7tpj44AALNBpQTn2lxX4d3e35Uh6arV P85lGUMEK3C7bmyYaXwaaVaPZJjk/ETAsf4hQr4raFcfuGmIaD6RJYadZZs5Qwb7j/rk GgpA== 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; bh=gRLn8qJuTlxCybT0NvPOQts7Km/pC8Xm3jqjjCzfF5Y=; b=aQBcworVEKyweT3xwMAIJj1DwtLitmRymYHUQAM8rTpofcnvlOR+3CGlhljoIubr0R 3r/j0QiAYbAMFrsVMYQdumlQh8bAtFyTTmFmxndprIGgsttXpAlJvyv57JdDg/jWr7fY bUYkQOGlzecp7zSdspEnCD7MSEEGk3OX44mPhiKdGL/URuDpF9tk+rjQV+VIPyub28bT d+IevoMERjuI6sXPqxbFYtvic6Sii+BmO0yZgmNArMmkOLTHJYeVgGPKfhA4hWixxrcg umFtcmE7NnHg7TFBP9LzpclmD6r0nq3yjG8cOh78zN0hG7aE/Sv0GhoHmSJW/lbuzrbv PFRQ== X-Gm-Message-State: AODbwcDDCHSQF+Q3JoydJb9RK8PP2bdOZkDm3n51SFxpa3GvmmR0h2eD jsPw5yIfd3y3Cw== X-Received: by 10.99.158.82 with SMTP id r18mr3024312pgo.231.1495093813402; Thu, 18 May 2017 00:50:13 -0700 (PDT) Received: from localhost.localdomain.localdomain ([101.204.217.146]) by smtp.gmail.com with ESMTPSA id q82sm8796689pfl.28.2017.05.18.00.50.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 18 May 2017 00:50:12 -0700 (PDT) From: linzhang To: aar@pengutronix.de, stefan@osg.samsung.com, davem@davemloft.net Cc: linux-wpan@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linzhang Subject: [PATCH] net: ieee802154: fix net_device reference release too early Date: Thu, 18 May 2017 15:50:07 +0800 Message-Id: <1495093807-11000-1-git-send-email-xiaolou4617@gmail.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-wpan-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch fixes the kernel oops when release net_device reference in advance. In function raw_sendmsg(i think the dgram_sendmsg has the same problem), there is a race condition between dev_put and dev_queue_xmit when the device is gong that maybe lead to dev_queue_ximt to see an illegal net_device pointer. So i think that dev_put should be behind of the dev_queue_xmit. Also, explicit set skb->sk is needless, sock_alloc_send_skb is already set it. Signed-off-by: linzhang Acked-by: Stefan Schmidt --- net/ieee802154/socket.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/net/ieee802154/socket.c b/net/ieee802154/socket.c index eedba76..a60658c 100644 --- a/net/ieee802154/socket.c +++ b/net/ieee802154/socket.c @@ -301,15 +301,14 @@ static int raw_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) goto out_skb; skb->dev = dev; - skb->sk = sk; skb->protocol = htons(ETH_P_IEEE802154); - dev_put(dev); - err = dev_queue_xmit(skb); if (err > 0) err = net_xmit_errno(err); + dev_put(dev); + return err ?: size; out_skb: @@ -690,15 +689,14 @@ static int dgram_sendmsg(struct sock *sk, struct msghdr *msg, size_t size) goto out_skb; skb->dev = dev; - skb->sk = sk; skb->protocol = htons(ETH_P_IEEE802154); - dev_put(dev); - err = dev_queue_xmit(skb); if (err > 0) err = net_xmit_errno(err); + dev_put(dev); + return err ?: size; out_skb: