Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7152375rwp; Tue, 18 Jul 2023 10:47:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlF+GTCFOLhlRAOKc5RgKPiNMbErG7k41SDG/Wk/9Q10C0fcXBoGblKmAxpyGNq1hGIyl2w9 X-Received: by 2002:a05:6a20:7d9d:b0:133:6e3d:728a with SMTP id v29-20020a056a207d9d00b001336e3d728amr29670pzj.6.1689702445521; Tue, 18 Jul 2023 10:47:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689702445; cv=none; d=google.com; s=arc-20160816; b=pdCr8ztogLZtnxE3pTxw9EKnfjH0+7jH/VVtra220FaHjqbBPk0zmoJZyBkFPR2ia9 jc24RApRY2iN6oBZjWVcknjv8tCyOe9S6Nc0Vn/UK2V+jg302t9wfZWf5Lsm2JRcTBa2 +Z4P87D3u86UOnuj7+8QLqoT9gI6JURvEPIdCyMw69Gy1c72mTiAqmv1YvNyFOQSOeST ScHRJL3eFuhGqlqZKEy71tVs0zj2OyGg3AzoaCI7vwKEfobNPmU0RKaOjkqvvnhkBKR2 HkCJyK2E32IPHtMebBbLRzm622bqXTiFhPh4haODdE2PDxKdX4KCsu0Z06BoNl0fZNyl qVCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=BBW2S/JWpSf6xBXHLFuXK/4q60GLP+u+nkzPfJJjU8k=; fh=7FP2fq6E2pF8GKwToLc295yvXVzOrmi5YSPyf/Jsd7E=; b=ylwY208OPu4A91EMXkEe+yuSIAlIhm8ypLt6+1GcgbGZm3RV3fwOIzOAQkLE3P4OQp OLa7YfXQP/rln5pH61V7Tc2fRDkh/l/Q1FvmPyunkxfMRFJnqK6HqA7aMOIhiwHKtzt5 XOOanma1eqI1+hywa6JNQqL7kveQ4NCOd5sVU3gp2b5T++Iccp+qoHD3ZGApzhKZV4UW VEaKI1ksIfq+B3OgZAQEJFyLenx54cl8ozBHR4NFEN1kV5XRnnoWhVe2eGS77Y8yBLjp f+dvwOGBeb4tVa5x7nfLQkHgwxC+c9XrCgX/V7Rr354Le4VNm3A4o+N0b5nXsamlQfMU 1/OQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gpeL3kTR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g130-20020a636b88000000b0055c96379d01si1912857pgc.705.2023.07.18.10.47.11; Tue, 18 Jul 2023 10:47:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gpeL3kTR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233121AbjGRR0C (ORCPT + 99 others); Tue, 18 Jul 2023 13:26:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232569AbjGRRZ6 (ORCPT ); Tue, 18 Jul 2023 13:25:58 -0400 Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7126BE; Tue, 18 Jul 2023 10:25:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689701157; x=1721237157; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=c2mlWNa1d/FZEIiXwHOg+EoY8yT+5U1KLwWZO6gycOs=; b=gpeL3kTRGl0gXRN8kQaVGgwTQYH/RBtLmqysM6XSqNLBn2SB8wpiJja+ HCY/gmrs//IoHWWyXwgUASuAf9fAAjYXI4hQV38vnkMO/SEa5NR+oDpws sLdS9BsBP4yXHxGwD5Vxbh94GhdQtsvrrFBJQEJJGYuXVNRweUORUILCf DOaSO5pZMD+P0yJITwsvzWqgf7eQq/RaROzrp1HOp0E9PvuI6n8MqYg+A tB/tfg1WrmIzgLMWAmFxiVUd9H97Q6ag6BijwzdueWWZDhADZ2jL6U8Po TQTFIvMRxW0iW4EhH+LNi23uRRWc66jkx3yUe/cjVPoBhIqmrV0q2ndsK w==; X-IronPort-AV: E=McAfee;i="6600,9927,10775"; a="397111492" X-IronPort-AV: E=Sophos;i="6.01,214,1684825200"; d="scan'208";a="397111492" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2023 10:25:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10775"; a="674004131" X-IronPort-AV: E=Sophos;i="6.01,214,1684825200"; d="scan'208";a="674004131" Received: from smile.fi.intel.com ([10.237.72.54]) by orsmga003.jf.intel.com with ESMTP; 18 Jul 2023 10:25:55 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qLoSP-005hx6-30; Tue, 18 Jul 2023 20:25:53 +0300 Date: Tue, 18 Jul 2023 20:25:53 +0300 From: Andy Shevchenko To: Milan Zamazal Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron , Lars-Peter Clausen , Nuno =?iso-8859-1?Q?S=E1?= Subject: Re: [PATCH v2] iio: core: Prevent invalid memory access when there is no parent Message-ID: References: <20230718152917.435962-1-mzamazal@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20230718152917.435962-1-mzamazal@redhat.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 18, 2023 at 05:29:17PM +0200, Milan Zamazal wrote: > Commit 813665564b3d ("iio: core: Convert to use firmware node handle > instead of OF node") switched the kind of nodes to use for label > retrieval in device registration. Probably an unwanted change in that > commit was that if the device has no parent then NULL pointer is > accessed. This is what happens in the stock IIO dummy driver when a > new entry is created in configfs: > # mkdir /sys/kernel/config/iio/devices/dummy/foo > BUG: kernel NULL pointer dereference, address: ... > ... > Call Trace: > ... > asm_exc_page_fault > container_offline > __iio_device_register > krealloc > iio_device_attach_buffer > iio_simple_dummy_configure_buffer > iio_triggered_buffer_setup_ext > iio_dummy_probe > iio_sw_device_create > device_make_group > configfs_mkdir Please, remove more unrelated lines in this backtrace. Ideally it should come to ~4-5. For example, you posted a command line, it's obvious that you run configfs, so the last (two) line(s) of the backtrace are redundant. Then drop basic stuff, like: asm_exc_page_fault container_offline krealloc Then remove unrelated IIO internals. > Since there seems to be no reason to make a parent device of an IIO > dummy device mandatory, let’s prevent the invalid memory access in > __iio_device_register when the parent device is NULL. With this > change, the IIO dummy driver works fine with configfs. The code wise it's okay now, so after addressing above Reviewed-by: Andy Shevchenko -- With Best Regards, Andy Shevchenko