From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0B65C2C028F for ; Wed, 28 Jan 2026 11:38:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769600336; cv=none; b=PaIpQEKyhV7DUbw/BNPWMyvjRzq69cFecp2x09GN2sZfOB9UV1SizvFJVmBuU3hOsP9irizQJ4ln72SHStzpe3AW+cqLRVyOTpsdISli0SKCSlPe3BdCFzXPkIrfxAsyIMGP725SDSwJp2XO6F5QNgu+aHPooR18jBsVjOxhHqA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769600336; c=relaxed/simple; bh=lfuWLe4KS5rkXy40zLgUOIVrYwlwq+Chml2mAIOo8Pk=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Afwzlc3SXBvFqa+VmitA56tx0PaevPLwWpIPUciaMg6emyBE/TupbfEz2uiMZJtA10uy0kfAzf1nuSfTShu4UkaIHs64j4N3fIv421b6U4+Cy9IFOeqQUd/bBnN49E+7zjORBEbgCratKRMWRMyi8CyUY7m6OYnUK//ngPZm+tc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=cdZP4coa; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="cdZP4coa" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4806f80cac9so3172265e9.1 for ; Wed, 28 Jan 2026 03:38:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1769600332; x=1770205132; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=S43whySCBobAQSsg9LI7G5jPjE8Dcko+pumH3bfe68c=; b=cdZP4coaXUvgutZ2E3yVL0Scrxn1TltNky5Nk2o6so2XggglJQltIRAN+z0NfdPqlM V8vDKHwIN6el7jw9MEJE1yMX6oG9XrProjx8ZbMUVIUgZuwz/6y7k4APN7Uzb+sZKodl PFjgegnN8uHAe2x3MXFrct5LxH13vW+XXaeyTV25fd+1l+DgdB1zx32fAjLB+VjFA4j0 S0sSXGm5svq8YpGTWwSaJW5eTS70o6hXoE7GP2TwWlb6TxRlQFnM4cdEvtlbTKL7HWr/ +apyw9hxH3R1jpwCeol1Gh16dfT3orXzwwL8rPwCHn4B/orgzZsEBRoXNaZ7MHTtknrK tObA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769600332; x=1770205132; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=S43whySCBobAQSsg9LI7G5jPjE8Dcko+pumH3bfe68c=; b=Tc4bj8szZVP6IimTyzFG3ORrZsaViUVmuk4U6sdm0WQ23WW7kX8aMtvkyNkEvxXYhr flxmbb9phC9slfcBwvQ2BAfcZEe8Rk6ewuUpOxZg0XEMn+2d/EbgRZq7/6jMGf4TKMil tm3X6Wn52USNsj1uGhs1Rcl1qULg8FkdYGv0QS1UZ5gYAaeJx6+G/+yW13NGdU8g9wo3 5PohT6Y39Q/51zM+1nLBCb08oYm3+oHAoJqVD3KMeSE3XucrRIpJxE/vzWTrTuY8+8v5 qbDw3WfdBeSkBKxUto7PxzhP3tZm6jIvBarHjqDMyQt2v4PGtlDwQaTQEsVVv4mSpGKy SdJQ== X-Forwarded-Encrypted: i=1; AJvYcCVmlSPzrarqVxkO0jEyO3D1zf2/e0Ahn/lqQ28vPhke5j52hYCFGBpkKHUnX0X5o7KbRuUifu+x5CbtmlY=@vger.kernel.org X-Gm-Message-State: AOJu0Yw1fDm1Yqx7mNi/Epvl1GWV6olR028EZUmwkt6bLeO28+wQAk7V xg0nRdWoW4GTzooxESW+E1jKIoACkfW8vg3sl76olgYUzJ6tKUKrWaNC06Qz0ZrANWM= X-Gm-Gg: AZuq6aLuI358VY46lNYTdjvq3X2orV5tMKbcOIWTObe2siua3J+qDr5MUPnkwodbH4Z rwp/Lbx0285PKM6b/N+784WsY/UtqQzyz+V6+gAcuZormhgxYFl2yDwUJDdRAgarzLDTlGcHS9q l4EUdnjK5kdgJjTe9T68nwtWcPZ93KzdkuQEqJ5SP8Syajvzukyc34/0JgzB9ZLk72yitjb73nV B0yp1EkSzHMfZQSy6cpscBHJ6hdiXW+sKu3rg+ieL3sMpjub5e0ZmFJosOPQsDWJALSRKdBcSC8 qtA5+Dju9wwAM+JDjKJ5gfvo4K8fdbi48FUEevwKm+keQZDGS0SMueWaZMSjGMyFjew8qujHj4Q VVTYHPcoZzv7d04ograDJj+xw/AtB3T8eFZ1qWZSFzQ+eS37iNFo+f3HaZhkr5zr96LxvKyV/oP f1JZsfP4Mjrc+BEbkt X-Received: by 2002:a05:600c:4fd4:b0:47e:e779:36d with SMTP id 5b1f17b1804b1-48069c8c23emr56137025e9.23.1769600332276; Wed, 28 Jan 2026 03:38:52 -0800 (PST) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4806ce5ec6bsm65536245e9.15.2026.01.28.03.38.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Jan 2026 03:38:51 -0800 (PST) Date: Wed, 28 Jan 2026 14:38:48 +0300 From: Dan Carpenter To: Minu Jin Cc: gregkh@linuxfoundation.org, bqn9090@gmail.com, abrahamadekunle50@gmail.com, straube.linux@gmail.com, bryant.boatright@proton.me, davidzalman.101@gmail.com, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] staging: rtl8723bs: fix potential race in expire_timeout_chk Message-ID: References: <20260127131035.731607-1-s9430939@naver.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260127131035.731607-1-s9430939@naver.com> On Tue, Jan 27, 2026 at 10:10:35PM +0900, Minu Jin wrote: > The expire_timeout_chk function currently do lock and unlock inside the > loop before calling rtw_free_stainfo(). > > This can be risky as the list might be changed > when the lock is briefly released. > > To fix this, move expired sta_info entries into a local free_list while > holding the lock, and then perform the actual freeing after the lock is > released. > > Signed-off-by: Minu Jin > --- > Hi, > > I noticed this lock-unlock pattern in expire_timeout_chk() while > studying the code and it looked like a potential race condition. > > I've refactored the code to use a local list so we can handle the > cleanup after releasing the lock. What do you think about this approach? > > Any feedback is appreciated. > > drivers/staging/rtl8723bs/core/rtw_ap.c | 19 ++++++++++++------- > 1 file changed, 12 insertions(+), 7 deletions(-) > > diff --git a/drivers/staging/rtl8723bs/core/rtw_ap.c b/drivers/staging/rtl8723bs/core/rtw_ap.c > index 67197c7d4a4d..5947f6363ab0 100644 > --- a/drivers/staging/rtl8723bs/core/rtw_ap.c > +++ b/drivers/staging/rtl8723bs/core/rtw_ap.c > @@ -179,6 +179,9 @@ void expire_timeout_chk(struct adapter *padapter) > u8 chk_alive_num = 0; > char chk_alive_list[NUM_STA]; > int i; > + struct list_head free_list; > + > + INIT_LIST_HEAD(&free_list); A couple minor style nits. Use LIST_HEAD(free_list) to do this in the initializer. > > spin_lock_bh(&pstapriv->auth_list_lock); > > @@ -190,19 +193,21 @@ void expire_timeout_chk(struct adapter *padapter) > if (psta->expire_to > 0) { > psta->expire_to--; > if (psta->expire_to == 0) { > - list_del_init(&psta->auth_list); > + list_move(&psta->auth_list, &free_list); > pstapriv->auth_list_cnt--; > - > - spin_unlock_bh(&pstapriv->auth_list_lock); > - > - rtw_free_stainfo(padapter, psta); > - > - spin_lock_bh(&pstapriv->auth_list_lock); > } > } > } > > spin_unlock_bh(&pstapriv->auth_list_lock); > + > + /* free free_list */ Delete this comment. It's obvious. > + list_for_each_safe(plist, tmp, &free_list) { Use list_for_each_entry_safe(). regards, dan carpenter > + psta = list_entry(plist, struct sta_info, auth_list); > + list_del_init(&psta->auth_list); > + rtw_free_stainfo(padapter, psta); > + } > + > psta = NULL;