From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 0046738655C for ; Tue, 14 Apr 2026 07:56:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776153364; cv=none; b=ngzJUvYCRKdSiAJxWCmdzUN3uLcx/zviTUZjaXMhD+uSk5TvSiBvZ+j/5mRkvn6P/xTUYA4ONsvhioe5HJiRTmlK80xtWHYaiD7JstNW0b2P33zqyNACzLRsipT65bhY0Q6XEh7PyfptchZT5izde/DFYnYBpMbjtd0AQwSLnfY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776153364; c=relaxed/simple; bh=EO61ndOQWekXegEyX5t1VPcc5albENG0PHNwbyqWxsU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NY93JgAgMpg+nXkMZqzkK4Mtl5kag4/O8cfxPzBAzwf7vvnlw5VeDntnlg67HqQfvS/MutFMxcTyjBB/A6I4QBAikBdHSfWkZNoHDzqWVu7JG01OOGtdgNXcgJvvL+gooJcOWnTY018a0xSSmNdKVx7DcdLVWX19Z/MXpQ3DxQ8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fgi57JRx; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fgi57JRx" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4852a9c6309so49773415e9.0 for ; Tue, 14 Apr 2026 00:56:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776153361; x=1776758161; 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=axgVeh28yHClCYz0L8M4AbQLJql6b8YevUT+Lu5qK7c=; b=fgi57JRxXAUDMDSvzXaLBUQ2BtecHjMveanKEucG0xIeXPmJHUj+mIkFjbB+YK4Uwe QJLnWhsqNm+ili2teqWbmZmi2u0Kvk4vdkpcXsX0pLMRmTbaNoTVEFuOJvatRMJTM3eY 7cye7JywI7L+Eot/2UOJ5GWgIhu8TAaO+nuGqvPideHBYhjQnHBA0zU+xbS+07bYk5lb V78gNGyRU+W8529P4SJmbmpXeoaXHW/nNKUpfw+xAcYK3CsJQhizendWRIqNK5Z3FEw0 OleGvJ+OgtbScLAASh6b/051pd8E7+rhgUvupFrTvaRrUVIr3HnB1F044MNLhLtYwhqc 53YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776153361; x=1776758161; 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=axgVeh28yHClCYz0L8M4AbQLJql6b8YevUT+Lu5qK7c=; b=gPc0JL86XiVHJarTleNsKMLNqUXPykzupPbdn61eetxEeJncsDpxW0jmLpnt+eaExq pDABOy9AEVFj8dXdrpNrcZP8Pkw/anjO4yjKxLegdBcRJo8tk0PrHEuUtZFQbohSYJ3a XHbrwSyK5HCVE/g5pk5zZvtb7Au+FxZqayrB7qHt+uKUnJ36NOYcHgQOsXb48RcmUoVn trm/+nImscapLwOwEG7nUTnksPEBjGEsI9M/aBN6B91cKT1QbW8HX5S3o3XM9UV70Cqb L1+yNofGlyE3vZ8q9uuC3DvXBqQAjf02PkxYBZjYJj9gKYujF8/D1RQet9vLCTsSCzC6 3deQ== X-Forwarded-Encrypted: i=1; AFNElJ+doNy3yBQW7cchSz4s0nAjdHLi/dtESPBRIELNES8wUlJ9QSpERSzdmvYnMKXBTIP98KHGHoS0nkJj/IQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwgmaxD40OYqjb4Hnu8+zl3aqIlZxU00FZ3GB6Td48J8pY+oB+p Sy6Fqm0LNvgSs03RpStz0hZ5YErUAb6ijdJaUSO3iANG8lFrJJXFdO5x X-Gm-Gg: AeBDiesbFGuTj2+5TozMbhcB7iSfNQ1Jq21Fd4DPKugasJdaSb2aDodFwGMdcn+vUbS 6VkBW6JgaI8l3yvC1+haf4ptrWfwPW+OeOYKzkSLPtHywlo+5ngCeH7PopW83bKYE5kbeF2uqny 3B//V78CoN5A39E7rpxmyLQz+umDQ0N0Z7xa3JpBjROqW2dFXvp38mdXZazs7ZGt3KlGJ0ctt49 +Hfsys35ttuqrQI6SpzXp23oEjF7pXiGUU7+TS0BE5OkISn0jdJ3FL+KFjOoqhHNU5zT71I6u6J OdIGyQWTOJgYrV4JzkHfAVJpQJyTYfeZyndkxCYeyhdQu3ItBQU5mLHaLx7o5iZzKEhGpWaoYmk RQcMsYfH5znKr4QZ2Ec2zghva4LKtVfccXzBpTb6ofi3xdnwgBewmaIbIbk9ZVm1BeS5v3XtAR8 daA0B2+mVEyNE9UKsH8xeLftkeCpMyRqdxIN+m X-Received: by 2002:a05:600c:3f19:b0:485:3ff1:d5ed with SMTP id 5b1f17b1804b1-488d67bbc2amr205094565e9.1.1776153361269; Tue, 14 Apr 2026 00:56:01 -0700 (PDT) Received: from localhost (hf33.n1.ips.mtn.co.ug. [41.210.143.51]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488ede24eb0sm32070755e9.8.2026.04.14.00.55.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2026 00:56:00 -0700 (PDT) Date: Tue, 14 Apr 2026 10:55:56 +0300 From: Dan Carpenter To: Andy Shevchenko Cc: Shyam Sunder Reddy Padira , gregkh@linuxfoundation.org, ethantidmore06@gmail.com, nayana.mariyappa@gmail.com, s9430939@naver.com, kees@kernel.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] staging: rtl8723bs: os_dep: avoid NULL pointer dereference in rtw_cbuf_alloc Message-ID: References: <20260413224417.5674-2-shyamsunderreddypadira@gmail.com> <20260414071308.4781-2-shyamsunderreddypadira@gmail.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: On Tue, Apr 14, 2026 at 10:46:13AM +0300, Andy Shevchenko wrote: > On Tue, Apr 14, 2026 at 12:43:06PM +0530, Shyam Sunder Reddy Padira wrote: > > The return value of kzalloc_flex() is used without > > ensuring that the allocation succeeded, and the > > pointer is dereferenced unconditionally. > > > > Guard the access to the allocated structure to > > avoid a potential NULL pointer dereference if the > > allocation fails. > > You have a procedural issue here: please avoid sending a new patch version in > the same email thread. It makes things harder to follow. For example, I usually > mark the entire thread as read if I see some comments and don't want to go into > the details. It effectively means that I will never see the new version that > already was in the same thread! > > ... > > > --- a/drivers/staging/rtl8723bs/os_dep/osdep_service.c > > +++ b/drivers/staging/rtl8723bs/os_dep/osdep_service.c > > @@ -194,7 +194,8 @@ struct rtw_cbuf *rtw_cbuf_alloc(u32 size) > > struct rtw_cbuf *cbuf; > > > > cbuf = kzalloc_flex(*cbuf, bufs, size); > > - cbuf->size = size; > > + if (cbuf) > > + cbuf->size = size; > > > > return cbuf; > > Now to the code. This is still buggy. The problem is that the size is not > validated and when it's 0, the same issue (dereference of invalid pointer) > will happen. > > Dan, JFYI k*alloc*(0) returns not NULL and not valid pointer. kzalloc_flex() basically can't return the ZERO_SIZE pointer. You would need to pass an empty struct, which is really rare. It can't that here for sure. regards, dan carpenter