Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp569751imm; Wed, 20 Jun 2018 03:06:39 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKr1Q9m8do8w8z39FrkyKoc4iqOKilSAON0TkCsnwVTbQ2nmjk9jcNKPKcnpFFeLTaDF8HT X-Received: by 2002:a63:6d0:: with SMTP id 199-v6mr17874874pgg.338.1529489199093; Wed, 20 Jun 2018 03:06:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529489199; cv=none; d=google.com; s=arc-20160816; b=r9cSEJJ2IpjLZ7G4V70UKjO+6Ta4MsXoh/6n+ZUW+QnLR/4CDzj8ko9R/ktlENcGAa RoiTJaxcWGEgDcIqLI7MypJhC5FGEAPs1NbepAF52Oa+k0nvboAXjJq/kH/hAfhX7KMG fYAG1EIBGwu6+aHVVwDoWfrA9WULQ8WBOHijicVy5I0SMqYxGfiAbYL7GS11Szzbkdj/ aTvjcUhwOSONQu06zA4i3Pzn9fTB8m+Qb72v4EHyqr7f3k/OKTKRnL9t2SWw/gEJjKkF uq75SG1oViR2nMOch8+67OEDdB8Hpd6cPfGSIBzWazt+C8v4jJaZ+sDyHq49wSKnQ5HA 2I6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=ybZ6l0/FKbOA/dhRErV7E4i06mHDeHq7tUIEdJJDjVc=; b=ruix5UkQ/jsI4x7U0prfKUMUIu15Kqtnld1pZr9Hd28pNPYyBjAKcJZ/mmWwGsixjf yC4CGlHOATz8w7lNWRynCNp9f7GMxVedWVuou+JHOqdeaMB8UnUfdhc1Al9khpeic522 anI7XNW/QJ/9l8cEW9XHCoOmZvx1VEw/mr0WY+6MAksl03sGB4yl7dnjRCWdPSU9THEl pZKVC9nAdjAYNdiFi7oH8A7rGLygMggRkOYaKarVssSJbHbzIufmNOE+bDqZoJ/Kg7Tb 9PBGsZEbp6JLjjkltBORZpkp+Ia8dGzvZYCC9ivCu/qX8Kx3hptAPzIUXB0vFFmHCpvT o7vg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="g3MKz/rL"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e12-v6si1666970pgn.171.2018.06.20.03.06.24; Wed, 20 Jun 2018 03:06:39 -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=@gmail.com header.s=20161025 header.b="g3MKz/rL"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754059AbeFTKFm (ORCPT + 99 others); Wed, 20 Jun 2018 06:05:42 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:36864 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750821AbeFTKFj (ORCPT ); Wed, 20 Jun 2018 06:05:39 -0400 Received: by mail-pf0-f193.google.com with SMTP id y5-v6so1362570pfn.4 for ; Wed, 20 Jun 2018 03:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=ybZ6l0/FKbOA/dhRErV7E4i06mHDeHq7tUIEdJJDjVc=; b=g3MKz/rLD3wxc1Cp1K6/6xItkcLDpBLYjUu/B+QosH71gaxpHSjwnZ1ZUjYu7NAcI/ obRPfSFlU+jJQO349xYAwTfPFJU4njKeefWgqxdJSADPgA1BT+pmDYntj3IFVBKq6G2V PsQpndt0nAOT2Q01pzBi26OlltFekx/ssGAtIXdI+sDZuRrkTO4Gsv1MT5LxU2zixMsV pBAI9yUS6j0OqHOQHjhV0SE6rUsDryDjrWgha2IPqNy3ptqSY7Gk4qiAG9z5ohT0H0yL vllCLOylCpA5k849XUWHUwBZSAGUrhm0Wlzt6wMJqk8stwvVABPpgfkJ38RjvoomtaCD /xjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=ybZ6l0/FKbOA/dhRErV7E4i06mHDeHq7tUIEdJJDjVc=; b=pg0KzXZ5CBlwzvTt7nj+nF+YRgV/EQoPF5ko/Ow+IOGsjTFplaWDnsspd0eeYPWTbm dalswRgiKmceruuPqSrIggJLLQLeVAmLgcls5Vp7ZMy/CSnS5azp36Q6LnPgSivSSLcg gM+PJnArxeJ39UeNSoh/UfoCbgrrKMr014G9ArYHX3v4JESvu1WZErnDZbeaVzWbklGZ uTMk1Jq6T+pr3NMjGI7IP6z8x28FJT/ts0s8pz0WBF9/wYK450caPMdLHgYs41elErSq cV2eZJ0H0Olq0Oeteu5ihtge61EvDEIsnaEDt6RS/M0kZ75owvcAlUr4t3gWDeIcl+qF usLg== X-Gm-Message-State: APt69E3yUAccobXa/wbes0x02K5UXBLcOJGt/HYjvhw8g2+oMhZ3/1Pl J3X9j9zAmDYIuYaXas9k4G06AZss X-Received: by 2002:a65:538e:: with SMTP id x14-v6mr18053625pgq.330.1529489138600; Wed, 20 Jun 2018 03:05:38 -0700 (PDT) Received: from ?IPv6:2402:f000:1:1501:200:5efe:166.111.70.11? ([2402:f000:1:1501:200:5efe:a66f:460b]) by smtp.gmail.com with ESMTPSA id g4-v6sm1924943pgc.8.2018.06.20.03.05.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jun 2018 03:05:38 -0700 (PDT) Subject: Re: [PATCH] staging: rtl8723bs: Fix two possible sleep-in-atomic-context bugs in translate_scan() To: Dan Carpenter , cocci@systeme.lip6.fr, Julia Lawall Cc: gregkh@linuxfoundation.org, quytelda@tamalin.org, Larry.Finger@lwfinger.net, harshasharmaiitr@gmail.com, arushisinghal19971997@gmail.com, amitoj1606@gmail.com, jeremy.lefaure@lse.epita.fr, teo.dacquet@gmail.com, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org References: <20180620095016.8484-1-baijiaju1990@gmail.com> <20180620095650.fga6xi7fyjgybs76@mwanda> From: Jia-Ju Bai Message-ID: Date: Wed, 20 Jun 2018 18:05:06 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20180620095650.fga6xi7fyjgybs76@mwanda> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/6/20 17:56, Dan Carpenter wrote: > On Wed, Jun 20, 2018 at 05:50:16PM +0800, Jia-Ju Bai wrote: >> The driver may sleep with holding a spinlock. >> The function call paths (from bottom to top) in Linux-4.16.7 are: >> >> [FUNC] kzalloc(GFP_KERNEL) >> drivers/staging/rtl8723bs/os_dep/ioctl_linux.c, 323: >> kzalloc in translate_scan >> drivers/staging/rtl8723bs/os_dep/ioctl_linux.c, 1554: >> translate_scan in rtw_wx_get_scan >> drivers/staging/rtl8723bs/os_dep/ioctl_linux.c, 1533: >> spin_lock_bh in rtw_wx_get_scan >> >> [FUNC] kzalloc(GFP_KERNEL) >> drivers/staging/rtl8723bs/os_dep/ioctl_linux.c, 455: >> kzalloc in translate_scan >> drivers/staging/rtl8723bs/os_dep/ioctl_linux.c, 1554: >> translate_scan in rtw_wx_get_scan >> drivers/staging/rtl8723bs/os_dep/ioctl_linux.c, 1533: >> spin_lock_bh in rtw_wx_get_scan >> >> To fix these bugs, GFP_KERNEL is replaced with GFP_ATOMIC. >> >> These bugs are found by my static analysis tool (DSAC-2) and checked by >> my code review. >> >> Signed-off-by: Jia-Ju Bai >> --- >> drivers/staging/rtl8723bs/os_dep/ioctl_linux.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c >> index b26533983864..7632b8974563 100644 >> --- a/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c >> +++ b/drivers/staging/rtl8723bs/os_dep/ioctl_linux.c >> @@ -321,7 +321,7 @@ static char *translate_scan(struct adapter *padapter, >> RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_scan: ssid =%s\n", pnetwork->network.Ssid.Ssid)); >> RT_TRACE(_module_rtl871x_mlme_c_, _drv_info_, ("rtw_wx_get_scan: wpa_len =%d rsn_len =%d\n", wpa_len, rsn_len)); >> >> - buf = kzalloc(MAX_WPA_IE_LEN*2, GFP_KERNEL); >> + buf = kzalloc(MAX_WPA_IE_LEN*2, GFP_ATOMIC); >> if (!buf) >> return start; > Thanks! It occurs to me that another way to detect this bug is that > one of the allocations in this function already uses GFP_ATOMIC. It > doesn't normally make sense to mix GFP_ATOMIC and GFP_KERNEL when there > isn't any locking in the function. Yes, this pattern is interesting for bug finding :) But to fix the bugs of this pattern, we need to decide whether GFP_ATOMIC or GFP_KERNEL should be used here. Best wishes, Jia-Ju Bai