Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp2133433lqt; Mon, 22 Apr 2024 02:21:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUKiAuTUcrfpIJVAF9oC2v7f4r4TccT2+KTiv/bQJlOOpBm/qLucxaB7XeUUzrPUl+Pcmt2XLUz5h/8uiBqHcTFQLUobWjy6URkow0FoQ== X-Google-Smtp-Source: AGHT+IHZldUw54CCiEIFfrsx0wc0oEJrtBV4AbxLwHopaqKYMwCeUbjfIRsgNRHRCuxj80Zcps3k X-Received: by 2002:a17:902:efc7:b0:1e8:2c8d:b749 with SMTP id ja7-20020a170902efc700b001e82c8db749mr9697156plb.30.1713777687626; Mon, 22 Apr 2024 02:21:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713777687; cv=pass; d=google.com; s=arc-20160816; b=YfAMoNbdCmXMzmd9oxb8YM6mjZHpXQzD8mGvkVwJP2oN5JACkk1A7QaUTsuBivtUCY 8EJji4aFpWNOEPM1lREmCZ8dcmGoKQiprmXB48mXyOVpqtHd2ZiNhwzwRorXwdRDiKsH Fsacd/juhMa4Y2fubDIqJNSkuOSb0slYZlnIqEKC/mipsuukXrH30TWhzjxd8qmyCLQn 8ygpxMLal42y7p+9lB+9waTw4riyiPAOkQY57f8j8aE1KpLeW2ZqwSaSTKZrg2+xZzIN 8iW3LjokaADQw64g+Pz+1MJHpbbHA62/f4sernYxKQeRzUOzQ6MQME9phJz3BVUprLz9 LVDQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=/ZnoxVFzUVtLu3q7xW9sJ5GLT4SFuqdKJs6/1zLjzWo=; fh=wZGzu4d9oQHfpPNL8BlalrftecaQrBB1T6gt+biwRCA=; b=mdt4K7Hkx+8jlzTIPbU/fwTNjOkptMWjeTIrgAhlM7PiuQI5A6W7W4y9DWFYd7kHSX Obr4DFY0t65HCb5g6rQHqjvXShDh4R8aBxj7Xne4OC9JPGarTJEd7HkHghV4azE5Xhr8 B2OaEB7gO119kdVATT+8ucuygl3ZngqjM1YfVuhKR+t0W9D4SszRDvuy3nsGlEV8eE9+ AtIuB1ol4x9ikSZ3w4gPZ1ncQY8ltwuZnewkKsk0yUwI8D02dofqqCQn4irVXoZ5a06o lKWX00sHRi+JXlK/o+qbmMCZiEzV4M26JQCO4gN121namA5hqfP9mQ0NrWx5l/wSRqhh U8/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-153082-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153082-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id e12-20020a170902cf4c00b001e4b20b9f97si7554813plg.646.2024.04.22.02.21.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Apr 2024 02:21:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-153082-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-153082-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-153082-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 495CE282B44 for ; Mon, 22 Apr 2024 09:21:27 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD0B013D607; Mon, 22 Apr 2024 09:20:26 +0000 (UTC) Received: from bmailout2.hostsharing.net (bmailout2.hostsharing.net [83.223.78.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5A00131BAE; Mon, 22 Apr 2024 09:20:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=83.223.78.240 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713777626; cv=none; b=bC+cl7QpBFjrIDxDPMVdEmt+2/FEMRALdM1JNChYQ4KFTVoMFqApSCaBJBlrvil1q0eTvi0V4ktPjRL35rDw3HUwRD35zGLpwc+TEHGBQHI3bSXnWfQHNZagNFGcbOQGjyX/WT+n+oBFm4J9Kkw60TjVZmbcxJ2lADwzuO0sxCQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713777626; c=relaxed/simple; bh=T5tRASABoyAmF4/TwmiQdb4aSxJ5IjEe6kgVUHlghnY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=T1J9NVUEboMegjPA5eL2FD5jIY+vGAjX97VuS6NdsiEX/P21C0H4YOLuuUn7JVByy2iFm2gYBvN14aUnT1+dRbxt9ega9DyQvSwZsVQbONTXO5m2QNYF/UUBbzZ6CIo4FzVjuLxEIiLOgQByikl4Ao9bYElQQESCaQcDG9rbysA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wunner.de; spf=none smtp.mailfrom=h08.hostsharing.net; arc=none smtp.client-ip=83.223.78.240 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=wunner.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=h08.hostsharing.net Received: from h08.hostsharing.net (h08.hostsharing.net [IPv6:2a01:37:1000::53df:5f1c:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "*.hostsharing.net", Issuer "RapidSSL TLS RSA CA G1" (verified OK)) by bmailout2.hostsharing.net (Postfix) with ESMTPS id 2EF4A280108A8; Mon, 22 Apr 2024 11:20:16 +0200 (CEST) Received: by h08.hostsharing.net (Postfix, from userid 100393) id 03FB34D34A; Mon, 22 Apr 2024 11:20:15 +0200 (CEST) Date: Mon, 22 Apr 2024 11:20:15 +0200 From: Lukas Wunner To: Dan Williams Cc: gregkh@linuxfoundation.org, Pierre-Louis Bossart , Marc Herbert , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, linux-coco@lists.linux.dev, alsa-devel@alsa-project.org Subject: Re: [PATCH 1/3] sysfs: Fix crash on empty group attributes array Message-ID: References: <170863444851.1479840.10249410842428140526.stgit@dwillia2-xfh.jf.intel.com> <170863445442.1479840.1818801787239831650.stgit@dwillia2-xfh.jf.intel.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: <170863445442.1479840.1818801787239831650.stgit@dwillia2-xfh.jf.intel.com> On Thu, Feb 22, 2024 at 12:40:54PM -0800, Dan Williams wrote: > It turns out that arch/x86/events/intel/core.c makes use of "empty" > attributes. > > static struct attribute *empty_attrs; > > __init int intel_pmu_init(void) > { > struct attribute **extra_skl_attr = &empty_attrs; > struct attribute **extra_attr = &empty_attrs; > struct attribute **td_attr = &empty_attrs; > struct attribute **mem_attr = &empty_attrs; > struct attribute **tsx_attr = &empty_attrs; > ... > > That breaks the assumption __first_visible() that expects that if > grp->attrs is set then grp->attrs[0] must also be set and results in > backtraces like: > > BUG: kernel NULL pointer dereference, address: 00rnel mode > #PF: error_code(0x0000) - not-present ] PREEMPT SMP NOPTI > CPU: 1 PID: 1 Comm: swapper/IP: 0010:exra_is_visible+0x14/0x20 > ? exc_page_fault+0x68/0x190 > internal_create_groups+0x42/0xa0 > pmu_dev_alloc+0xc0/0xe0 > perf_event_sysfs_init+0x580000000000 ]--- > RIP: 0010:exra_is_visible+0x14/0 > > Check for non-empty attributes array before calling is_visible(). [...] > --- a/fs/sysfs/group.c > +++ b/fs/sysfs/group.c > @@ -33,10 +33,10 @@ static void remove_files(struct kernfs_node *parent, > > static umode_t __first_visible(const struct attribute_group *grp, struct kobject *kobj) > { > - if (grp->attrs && grp->is_visible) > + if (grp->attrs && grp->attrs[0] && grp->is_visible) > return grp->is_visible(kobj, grp->attrs[0], 0); > > - if (grp->bin_attrs && grp->is_bin_visible) > + if (grp->bin_attrs && grp->bin_attrs[0] && grp->is_bin_visible) > return grp->is_bin_visible(kobj, grp->bin_attrs[0], 0); > > return 0; I'm wondering why 0 is returned by default and not SYSFS_GROUP_INVISIBLE. An empty attribute list (containing just the NULL sentinel) will now result in the attribute group being visible as an empty directory. I thought the whole point was to hide such empty directories. Was it a conscious decision to return 0? Did you expect breakage if SYSFS_GROUP_INVISIBLE is returned? Thanks, Lukas