From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D969C4743C for ; Wed, 23 Jun 2021 15:11:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F8166112D for ; Wed, 23 Jun 2021 15:11:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231310AbhFWPNr (ORCPT ); Wed, 23 Jun 2021 11:13:47 -0400 Received: from mail.kernel.org ([198.145.29.99]:37902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbhFWPNq (ORCPT ); Wed, 23 Jun 2021 11:13:46 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 817B36100B; Wed, 23 Jun 2021 15:11:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1624461089; bh=nrvJ03WJxT1u5DpvKe8AOm5b/1uT3Kw3Au08RLSPaug=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KvxlS0WKBQLoF9tZaUTkYitgt3y9mLMASLVmfYrurORcj9vP8TgPJglZRhqg8SH7P lZsShvwdr0MCrbp7CTk7e8YgKNi56l/zEKFeeGe9R9Juj0QT0M1J9qgjnIl4qbPB6Y a6PvHy6rrpgyJXTvGeaj4FX/gz41hib3z3uPkNWg= Date: Wed, 23 Jun 2021 17:11:26 +0200 From: "gregkh@linuxfoundation.org" To: Christian =?iso-8859-1?Q?L=F6hle?= Cc: "linux-kernel@vger.kernel.org" , "rafael@kernel.org" Subject: Re: [PATCH] kobject: Safe return of kobject_get_path with NULL Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jun 23, 2021 at 02:47:35PM +0000, Christian Löhle wrote: > Prevent NULL dereference within get_kobj_path_length > > Calling kobject_get_path could provoke a NULL dereference > if NULL was passed. while fill_kobj_path will return > with a sane 0 for NULL, kobjet_get_path_length did not. Who passes NULL into that function? Shouldn't that be fixed first? > > Signed-off-by: Christian Loehle > --- > lib/kobject.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/lib/kobject.c b/lib/kobject.c > index ea53b30cf483..735159c13a94 100644 > --- a/lib/kobject.c > +++ b/lib/kobject.c > @@ -130,6 +130,8 @@ static int get_kobj_path_length(struct kobject *kobj) > { > int length = 1; > struct kobject *parent = kobj; > + if (!kobj) > + return 0; > > /* walk up the ancestors until we hit the one pointing to the > * root. > -- > 2.32.0 > > Hyperstone GmbH | Line-Eid-Strasse 3 | 78467 Konstanz > Managing Directors: Dr. Jan Peter Berns. > Commercial register of local courts: Freiburg HRB381782 > Pleaase always run your patches through checkpatch.pl so you do not get maintainers asking you to use checkpatch.pl... thanks, greg k-h