From patchwork Fri Feb 19 22:25:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 585470 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id CE553140213 for ; Sat, 20 Feb 2016 09:27:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b=Z24OWLuv; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1428037AbcBSW04 (ORCPT ); Fri, 19 Feb 2016 17:26:56 -0500 Received: from mail-pa0-f52.google.com ([209.85.220.52]:32863 "EHLO mail-pa0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2993238AbcBSWZx (ORCPT ); Fri, 19 Feb 2016 17:25:53 -0500 Received: by mail-pa0-f52.google.com with SMTP id fl4so57177919pad.0 for ; Fri, 19 Feb 2016 14:25:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=q6uAIXPSWX0OTO+X8NbriRWcXQEmz2NQCnqcYohZcmY=; b=Z24OWLuvdiNw7vFs/WMSokJpAgEHJiqHFEFW2WoONG3zv1J6EeYLZniNwwNBrdweOa w2KmHfLvLf4zNMbrQiQqvEKQN/ZpbJ/6WdSkHXYigXK4JitmdAlkOmS/cOzLZYhPGa9M Z2b2yp1TvPdqappVNmxVZvUprJe44jUipGswM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=q6uAIXPSWX0OTO+X8NbriRWcXQEmz2NQCnqcYohZcmY=; b=Bz7dRm0DNisdQyDEnJ4YuIrI0o8s3o02SPSxnKlG3R0+Xt8MLuX2Ir5DTaMQAJ4Qtq 3i7I0E+xnYavXqHQtNn3HYS/Q24hJTsQEeZaZEwIb4sqr9sYhzgsd3Y89PeUn0OW0QqI 3UsIy1oIp6Cqk7SNzJ6pAol4AWxlk/cxqLE1bqExyc4EZBsUp54CCGtpseas2UcHTwyB 0C4Zb4szwQWSNGLBI3Z2HZg7xKbjj9Htzs36+4aInVOJKHtJlzJiozYfACuNwtWDxOxk DpxdF+fDt0plRjgC3fod3ZVW/saGmJdKYc8GEfCPVIw2mr7hZfY6iV7u0c+uLAeHHpIW EI4w== X-Gm-Message-State: AG10YOQHcfv39B1RCKHypQGJjC6MrUkmNFVyTxRmYvS/dSh/odvUmvBIOvFVu/YBwKMZog== X-Received: by 10.66.220.66 with SMTP id pu2mr21381596pac.115.1455920753378; Fri, 19 Feb 2016 14:25:53 -0800 (PST) Received: from tictac.mtv.corp.google.com ([172.22.65.76]) by smtp.gmail.com with ESMTPSA id qj8sm20076320pac.40.2016.02.19.14.25.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 19 Feb 2016 14:25:52 -0800 (PST) From: Douglas Anderson To: Johan Hedberg , Marcel Holtmann Cc: Douglas Anderson , gustavo@padovan.org, johan.hedberg@gmail.com, davem@davemloft.net, linux-bluetooth@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] Bluetooth: hci_core: Avoid mixing up req_complete and req_complete_skb Date: Fri, 19 Feb 2016 14:25:21 -0800 Message-Id: <1455920722-20892-1-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In commit 44d271377479 ("Bluetooth: Compress the size of struct hci_ctrl") we squashed down the size of the structure by using a union with the assumption that all users would use the flag to determine whether we had a req_complete or a req_complete_skb. Unfortunately we had a case in hci_req_cmd_complete() where we weren't looking at the flag. This can result in a situation where we might be storing a hci_req_complete_skb_t in a hci_req_complete_t variable, or vice versa. During some testing I found at least one case where the function hci_req_sync_complete() was called improperly because the kernel thought that it didn't require an SKB. Looking through the stack in kgdb I found that it was called by hci_event_packet() and that hci_event_packet() had both of its locals "req_complete" and "req_complete_skb" pointing to the same place: both to hci_req_sync_complete(). Let's make sure we always check the flag. For more details on debugging done, see . Fixes: 44d271377479 ("Bluetooth: Compress the size of struct hci_ctrl") Signed-off-by: Douglas Anderson Acked-by: Johan Hedberg --- Testing was done on a Chrome OS device on kernel 3.14 w/ bluetooth-next backports. Since I couldn't reliably reproduce the problem, I simply confirmed that existing functionality worked. net/bluetooth/hci_core.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 541760fe53d4..9c0a6830ff92 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -4118,8 +4118,10 @@ void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status, break; } - *req_complete = bt_cb(skb)->hci.req_complete; - *req_complete_skb = bt_cb(skb)->hci.req_complete_skb; + if (bt_cb(skb)->hci.req_flags & HCI_REQ_SKB) + *req_complete_skb = bt_cb(skb)->hci.req_complete_skb; + else + *req_complete = bt_cb(skb)->hci.req_complete; kfree_skb(skb); } spin_unlock_irqrestore(&hdev->cmd_q.lock, flags);