Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp6785071pxb; Wed, 17 Feb 2021 13:25:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxeUphXBWhl6o2DsyX+HVON9tUPyFQOkGLoqBicP9FciddcqDUBBxpCVtN2tc03/IuiNuSZ X-Received: by 2002:a17:906:398c:: with SMTP id h12mr854075eje.469.1613597116255; Wed, 17 Feb 2021 13:25:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613597116; cv=none; d=google.com; s=arc-20160816; b=rOdDwtTxSpec6B4pKfdVajOFxTrojBPl1XSSmam95HVGQ0LS1WRGJB9tHJKT3RtxvF 0CjWjHRWeuEQU6S2IKSZpiDIvlPDpEOnEjw7w22r3nBrechm4CbyHFw9HPFi7uGd30yG FMJOJlIsyojB1BKN0rdVy825jvmxYgFB0dqxYnTP0CwukQYMKx7fcxMVlvgrYjajNens 1/g2SXuK/krcTF5OOVnX0WANUnNOStGg1tpC9pmLh0lVd5wJWItTAjnEpBw44DCfwNBl UC8dm6zcwk9vDngu8lMyL8GX++7iRPynbGkvypIGKh5ZGNHFdrtk8/caxuIQtvujxTCG EaoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=SPUsxNYOqrjc6yzppnQTsrX18OHvrnDQxeQrl3Z/QyQ=; b=e9lBzq6JNvcK6zQ38R9GzZwp0h+nqZ/KThhbY/SMZ6LGIsiGCB+A2yZTJD7XBgc9tv Gfvlq0C5X2eXl5rHJWX2YRzl5INlqUgBhJgyUkF6q0muUjOzIqkcvNJRXZkNosHd0GVp GuxTP+zkbdfBqFMx72BAGPXt3LGwM/0ZvxnOCi2V7O8/ra1fbe1MQrjEU2TDyFpamV79 XHpITFmjhOT9lZuqE13j4n6nHvh7vS/CYQqjFa03asY+hjAV9MndPEFrfdhgo6kvoWWJ ZIRT5MoeEoeGevfMsyNqNuZH9A2w78D0+q0ra++YRqmPDiHpflxgeKSooCxLIjqL888A J9AA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=UOzhDngD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ho39si2246159ejc.708.2021.02.17.13.24.52; Wed, 17 Feb 2021 13:25:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=google header.b=UOzhDngD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234294AbhBQU3O (ORCPT + 99 others); Wed, 17 Feb 2021 15:29:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234063AbhBQU3I (ORCPT ); Wed, 17 Feb 2021 15:29:08 -0500 Received: from mail-io1-xd31.google.com (mail-io1-xd31.google.com [IPv6:2607:f8b0:4864:20::d31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03AF3C0613D6 for ; Wed, 17 Feb 2021 12:28:27 -0800 (PST) Received: by mail-io1-xd31.google.com with SMTP id y202so6784240iof.1 for ; Wed, 17 Feb 2021 12:28:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=SPUsxNYOqrjc6yzppnQTsrX18OHvrnDQxeQrl3Z/QyQ=; b=UOzhDngDTYPyFp+8BBBv/5jwzLWBu6Pj+SJEp7sRSJv67zw1R50FNPBel8lvpfJsar 58P9swwlymB0Ns0IVqctY+GDabeXda+G5lLmEn+qZzXGk69e13EcBHJryUxB1MIHTOUQ jNObPNjioN90MW/eEriJTA9/PpYLPXfkETGBg= 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-language :content-transfer-encoding; bh=SPUsxNYOqrjc6yzppnQTsrX18OHvrnDQxeQrl3Z/QyQ=; b=rxES9jPUQ/JViExc5NmjP01ZVaR8UZ/4BGMa38xXLuxjb6rGlizYTf3vyB62z4LRDa Ut8gg7yRIf0vkLH+4JImcFuo5ThF6lz/JAxqNGV4+tI0GBZyBIenPo7w8bBDEk3WC8+N SzEt1LBjxuzJWbxuPqKaTyOu7PBvCY9kaPHI/OKord/wT+QbCfcD4eA/RonKwjJI2Yij T1YGFsHP/f/e/Sv0sC6HtClEyx2i/p/3hHRycIV+0Te6bd4iNvPAs4AxyLLENAAkd7s7 UtIQmidxaRDStdjGTeLWg0pN3cxKUzE269wHlDbbI2wDDcfABgx0dJczDKSzSI2iPoDj w5HA== X-Gm-Message-State: AOAM531e5kEbiJ+gNYPZLMABAZ3rto1lSz9BR1wMGzVIvqktIfXQwqsi P4qcQ+iE6t1LtYnPFP6owrMKzw== X-Received: by 2002:a05:6602:2e84:: with SMTP id m4mr654624iow.43.1613593707308; Wed, 17 Feb 2021 12:28:27 -0800 (PST) Received: from [192.168.1.112] (c-24-9-64-241.hsd1.co.comcast.net. [24.9.64.241]) by smtp.gmail.com with ESMTPSA id 144sm2195441ioc.41.2021.02.17.12.28.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 17 Feb 2021 12:28:26 -0800 (PST) Subject: Re: [PATCH 2/2] ath9k: fix ath_tx_process_buffer() potential null ptr dereference To: Kalle Valo , Felix Fietkau Cc: davem@davemloft.net, kuba@kernel.org, ath9k-devel@qca.qualcomm.com, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Shuah Khan References: <43ed9abb9e8d7112f3cc168c2f8c489e253635ba.1613090339.git.skhan@linuxfoundation.org> <20210216070336.D138BC43463@smtp.codeaurora.org> <0fd9a538-e269-e10e-a7f9-02d4c5848420@nbd.name> <878s7nqhg0.fsf@codeaurora.org> <6bbeb37f-620e-d92d-d042-a507bbb39808@linuxfoundation.org> From: Shuah Khan Message-ID: <5d70b0ab-0627-74a1-3602-98a7c71b871a@linuxfoundation.org> Date: Wed, 17 Feb 2021 13:28:25 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: <6bbeb37f-620e-d92d-d042-a507bbb39808@linuxfoundation.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/17/21 7:56 AM, Shuah Khan wrote: > On 2/17/21 12:30 AM, Kalle Valo wrote: >> Shuah Khan writes: >> >>> On 2/16/21 12:53 AM, Felix Fietkau wrote: >>>> >>>> On 2021-02-16 08:03, Kalle Valo wrote: >>>>> Shuah Khan wrote: >>>>> >>>>>> ath_tx_process_buffer() references ieee80211_find_sta_by_ifaddr() >>>>>> return pointer (sta) outside null check. Fix it by moving the code >>>>>> block under the null check. >>>>>> >>>>>> This problem was found while reviewing code to debug RCU warn from >>>>>> ath10k_wmi_tlv_parse_peer_stats_info() and a subsequent manual audit >>>>>> of other callers of ieee80211_find_sta_by_ifaddr() that don't hold >>>>>> RCU read lock. >>>>>> >>>>>> Signed-off-by: Shuah Khan >>>>>> Signed-off-by: Kalle Valo >>>>> >>>>> Patch applied to ath-next branch of ath.git, thanks. >>>>> >>>>> a56c14bb21b2 ath9k: fix ath_tx_process_buffer() potential null ptr >>>>> dereference >>>> I just took another look at this patch, and it is completely bogus. >>>> Not only does the stated reason not make any sense (sta is simply >>>> passed >>>> to other functions, not dereferenced without checks), but this also >>>> introduces a horrible memory leak by skipping buffer completion if sta >>>> is NULL. >>>> Please drop it, the code is fine as-is. >>> Felix, I looked at the code path again and found the following path that can become a potential dereference downstream. My concern is about potential dereference downstream. First path: ath_tx_complete_buf() 1. ath_tx_process_buffer() passes sta to ath_tx_complete_buf() 2. ath_tx_complete_buf() doesn't check or dereference sta Passes it on to ath_tx_complete() 3. ath_tx_complete() doesn't check or dereference sta, but assigns it to tx_info->status.status_driver_data[0] tx_info->status.status_driver_data[0] = sta; ath_tx_complete_buf() should be fixed to check sta perhaps? This assignment without checking could lead to dereference at some point in the future. Second path: ath_tx_complete_aggr() 1. ath_tx_process_buffer() passes sta to ath_tx_complete_aggr() 2. No problems in this path as ath_tx_complete_aggr() checks sta before use. I can send the revert as it moves more code than necessary under the null check. As you pointed out, it could lead to memory leak. Not knowing this code well, I can't really tell where. However, my original concern is valid for ath_tx_complete_buf() path. Sending revert as requested. thanks, -- Shuah