Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5729155pxj; Wed, 23 Jun 2021 07:49:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwoZucAexOTcHDFGQnMD75xAUSNp8ArXiV+nDWVPwo12EIm/wavzc9bmz1JqBSyVaMDZ+qy X-Received: by 2002:a6b:a10:: with SMTP id z16mr7408048ioi.70.1624459744485; Wed, 23 Jun 2021 07:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624459744; cv=none; d=google.com; s=arc-20160816; b=KFhFhAhakLAHM/w0+eER/q5FXLI1J8JzHRSA0VZd3l4bFh34or+oW6ps0VgTMDBb6S DOIdN7OGBw2J6mhIMkrxZxQhdhzcUaMT205eTZiwbU1wQpQ60TRDmgtFaLtKpK3wjdi6 /SvuQxrsZwZIfZIwEaN00O1tDSIWsE/Xf0YNSSaEqAVYJX0Q+NPyemoJ6Qh0eAB/ltAZ mOBNx7yP28WBvT8mEAfbHILDpQZXXxF7Opx/E/OUHeUu4XHpu5Oga1ogE+t208aC3yZR qJmbAz2PIJFb5cgyAUeGf78/AcOlJpEI3wESdrIK3VNmhyJw4ysPNIf3yFpQTIoT/bvo CxLw== 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 :mime-version:accept-language:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=f6kDH3FkHyaKqJx3aXgXPiO1NWECwE8r1/KWlu96THY=; b=FA4bNS8p2QwrQN0eQ8MACvhpQMjcOmGppJuRS3TpeDB1YJxB7SC0ZSbd4cCNITtSWf 9NsmsmZDC7lI32nTVpb1vsi2GeZhmL/B7Imp9s9j630sTKIu+BJht176KMD/v7HN/LLE dXQYazU+b309ryD8n3LxUHTuHEuXhbZlnDT/qZ6d5HziTKPc/lu0MOiAUwhRIQFAjHvA 7ql/JD4St3u8OXdQ85oXIq6aeNIBQeItbNHdwEv16LfKnF+GcHbmLROLPDnKjO2+UNMH s7oohPxuzCS9P/FyrXOUrKaUf4RGSxWC4Qmn9RT5+AYgUDyfOUvJfqaP6HiFIqK/QXnN DWrg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=hyperstone.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r22si230920jad.28.2021.06.23.07.48.52; Wed, 23 Jun 2021 07:49:04 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=hyperstone.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230449AbhFWOt5 convert rfc822-to-8bit (ORCPT + 99 others); Wed, 23 Jun 2021 10:49:57 -0400 Received: from de-smtp-delivery-105.mimecast.com ([194.104.109.105]:39843 "EHLO de-smtp-delivery-105.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230061AbhFWOt4 (ORCPT ); Wed, 23 Jun 2021 10:49:56 -0400 Received: from GBR01-LO2-obe.outbound.protection.outlook.com (mail-lo2gbr01lp2053.outbound.protection.outlook.com [104.47.21.53]) (Using TLS) by relay.mimecast.com with ESMTP id de-mta-29-AtaEgG65NR-SgCiQJLUBWQ-1; Wed, 23 Jun 2021 16:47:36 +0200 X-MC-Unique: AtaEgG65NR-SgCiQJLUBWQ-1 Received: from CWXP265MB2680.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:89::10) by CWLP265MB3219.GBRP265.PROD.OUTLOOK.COM (2603:10a6:400:be::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4242.18; Wed, 23 Jun 2021 14:47:35 +0000 Received: from CWXP265MB2680.GBRP265.PROD.OUTLOOK.COM ([fe80::259d:65ac:ae6d:409d]) by CWXP265MB2680.GBRP265.PROD.OUTLOOK.COM ([fe80::259d:65ac:ae6d:409d%9]) with mapi id 15.20.4242.024; Wed, 23 Jun 2021 14:47:35 +0000 From: =?iso-8859-1?Q?Christian_L=F6hle?= To: "gregkh@linuxfoundation.org" , "linux-kernel@vger.kernel.org" , =?iso-8859-1?Q?Christian_L=F6hle?= CC: "rafael@kernel.org" Subject: [PATCH] kobject: Safe return of kobject_get_path with NULL Thread-Topic: [PATCH] kobject: Safe return of kobject_get_path with NULL Thread-Index: AQHXaD5guylz4e+fzky/qfcToJhYzA== Date: Wed, 23 Jun 2021 14:47:35 +0000 Message-ID: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [185.80.168.10] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 8ac332ea-f663-415d-fd11-08d93655d6d8 x-ms-traffictypediagnostic: CWLP265MB3219: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:6790 x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0 x-microsoft-antispam-message-info: cY1fcBu4kMTVHLU84l9UoXZwNp4IeuOT4WCL7RkK5kV+wBYpscQtMeDiRSJY6xEiVVjJ0oHUhD1oJ3Kl5fEUxxUDKBjs5jJYqMg67cdEv+n4VsdXcGIhwS23gRa3sY5bw8YQFcSYL9Ukv4LJhAfJlanc8p3Cg1U9Gt6FymiP2nv1biuZxLBNDvJhizJ5dv74pOTRM7MPMqmuYG5Fr7gBfgGvG7AWGOuGwvQgVDYBFPSew+h54oCUC3kwVs1KkZhi/oIyUFapKct5scQMjdvhzByf6ZPHxSrEn+GD2F+fk6zhRi7k7ee/4/kFDo3efbPCfh88NlxhIR2BOtydBmTQh7IVT4hkAjxkoqbmt42mxQE7lDyvG3z9XkPqcPIpKuUFY3JSEs43nTqN7rGkBfOVLQbHz2LhderkJi2Jfam/sd4tfHi09zQ/KkWz6DRuoRjgEH4aqrQ7SzkVhKSwjP64j19QinItIAj+qhPtXw9SgycuL2i4BlEH2CeTAnE13n6GmTvwLWyFshIiNWJxRDbnNJjm7LmsXoEccTMbU3xI4JCxUasnyRtcqNSxH+u4NC8Mv30qTPutn1xpuhwXRBOkdc8kel5s9Uae59eJFpvSRmM= x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CWXP265MB2680.GBRP265.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(396003)(39830400003)(366004)(346002)(136003)(376002)(122000001)(26005)(66946007)(66476007)(64756008)(66556008)(316002)(66446008)(186003)(52536014)(2906002)(33656002)(4744005)(71200400001)(38100700002)(91956017)(9686003)(478600001)(76116006)(6506007)(110136005)(86362001)(5660300002)(8676002)(55016002)(7696005)(8936002)(4326008);DIR:OUT;SFP:1101 x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?Q?NuLa2C76zWYOwtzaAC/lckOg1ZDfJcIIRu5oBDdngEhTAy6a9NB/oDDo4h?= =?iso-8859-1?Q?K4vPyB2auuGnwEm/Dbg29sTifCZfvIFz99DfdQwAgN5ZuKGWM2flVDhwVh?= =?iso-8859-1?Q?jUr586cqHgMy/MrPl9bC+xzCCnK40CULEOfX0v/VhybumL7m/eXxbUCCFq?= =?iso-8859-1?Q?WdN5OScygdNH2QLGw9wTDlOuO1RgBUMUQ1myNPlnrM/K4NF6AOyEUD88AI?= =?iso-8859-1?Q?rgwxl7htvn/EJOtCjTvpKdWPwwNckJDb2TcqvkGxoGlMAXBtuonD0/CcZi?= =?iso-8859-1?Q?MQUyH/12jSe9N8yzEn/EhYUJyI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8859-1?Q?AHbU48UihHWj3QX5GkO8CvA1N+aj3DTt0AkEzJwwCWeqZiRccU2tVVPTb3?= =?iso-8859-1?Q?ABw0Q3OuhULVryET72LA3ZQyg0Fx8HEbkkDKvIRIl1fIH7ypPyJ36rL6lV?= =?iso-8859-1?Q?SFf8q0fR3oBdkUS53CpVosy4THYlA7tC0AIsNWpkx9nheIg=3D?= MIME-Version: 1.0 X-OriginatorOrg: hyperstone.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CWXP265MB2680.GBRP265.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 8ac332ea-f663-415d-fd11-08d93655d6d8 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Jun 2021 14:47:35.3464 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 86f203eb-e878-4188-b297-34c118c18b11 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: 7Ou7X38HYkM/pLSaHmaXXLgHMLN0fZ25b+eE52UP4qVk3L4eSaGtLawMPcTgcgqKwUSat0nXNx1312ERaY1RnQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CWLP265MB3219 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: hyperstone.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. 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