Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7207227pxb; Thu, 18 Feb 2021 04:31:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbtw2mZsERpkbVSN03XFkzN8Q3J18l4rmCUQsP+PsD8mj2oxyYLVSkmMlQBfR7aoslNtDb X-Received: by 2002:a17:906:bceb:: with SMTP id op11mr3722335ejb.113.1613651500624; Thu, 18 Feb 2021 04:31:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613651500; cv=none; d=google.com; s=arc-20160816; b=aWetReTw0RmnGGuFl8izY8VliatqSz61EaygEkVOOZPFYAU6RUy+2sBVWw0wYTyM85 QU1TsHZs5hcbzXkBxyJu3SMA3BuSL8lPMFnmDOFdlfgBZ3qgMzYTb4ZPvoOO0tzfJES9 KW157e75UbV4dzZahtvZqG52d/lT+UWmB8gW1A6fvIBXe+oqwnOfm8iGR2PT/5QEoWge hRnCfga/GswE+bxWPHW5f8+3n0yGHrzpEEF5jns16zs5BruXVdM2YiJW2djqrhW4Olsa Z9zW74l8joBKZkUWnqumodSEXVz9dSU0NDubFuopg+p6gSUWnwfj2H0NZiEvAFy0ZbF7 6bXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ZUYdGfBovPQofBTZOwpzeDRcMqQI0Cs/F1EUZmLN1Og=; b=XDq09K6zjR2AM11mutCOtMF3+A9iZ164Pa+PQ/CLvdmcgXqvnGjE9hOQXrjLusLuVg WMlKu5WmtQnOTLGYB/vNK2sB4GmrO4ebOVwUWRoWQb/S0O5wftrnsp9WDP+dJw+YKTPK Dy/DK6hK1zGQ6bZdGzCmR5CnIUgKmvqxPigI+Zo+fST46cLxoAs/Ngn96CC7voOKmMNu zNnkSsp3z72gwP58rzd/pZM3ejxxDjmVIiYOMlbg9uuBi+hANUuVwekwIXpeUZuc7eXk DT1x7igYXT73WIYqHr7P8cZzeBR5eoNrJ4FoaWdLJyz7gUjtF4620dAZ1UcB1FtqEBD5 K9Lg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b="j/Q23nWy"; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s14si3592496edr.75.2021.02.18.04.31.14; Thu, 18 Feb 2021 04:31:40 -0800 (PST) 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; dkim=pass header.i=@suse.com header.s=susede1 header.b="j/Q23nWy"; 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=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232840AbhBRM2i (ORCPT + 99 others); Thu, 18 Feb 2021 07:28:38 -0500 Received: from mx2.suse.de ([195.135.220.15]:38734 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232113AbhBRKp7 (ORCPT ); Thu, 18 Feb 2021 05:45:59 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1613645111; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ZUYdGfBovPQofBTZOwpzeDRcMqQI0Cs/F1EUZmLN1Og=; b=j/Q23nWy3DDqB0knZYFLM3ufccVH6Vlqjyra2RiO1s3T7UvBaB7b3ZemTGW7q68CP70eEU wg5LP8GGVgjojxP3IK1rSuckmoksDNdmSiTEUFU3PiM6dbdXk6O/j9UV+uZnxX2PRqeGjL 260IOflu7cjHtraYDwFafFfcr/wtxf4= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 1D530AE04; Thu, 18 Feb 2021 10:45:11 +0000 (UTC) Date: Thu, 18 Feb 2021 11:45:10 +0100 From: Petr Mladek To: Chris Down Cc: linux-kernel@vger.kernel.org, Sergey Senozhatsky , John Ogness , Johannes Weiner , Andrew Morton , Steven Rostedt , Greg Kroah-Hartman , Kees Cook , kernel-team@fb.com Subject: Re: code style: Re: [PATCH v4] printk: Userspace format enumeration support Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed 2021-02-17 16:32:21, Chris Down wrote: > Chris Down writes: > > open(f); > > debugfs_file_get(f); > > fops->open(); > > inode->private = ps; > > debugfs_file_put(f); > > > > remove_printk_fmt_sec(); /* kfree ps */ > > > > read(f); > > debugfs_file_get(f); > > fops->read(); > > ps = inode->private; /* invalid */ > > debugfs_file_put(f); > > Er, sorry, inode->private is populated at creation time, not at open(). The > same general concern applies though -- as far as I can tell there's some > period where we may be able to _read() and `ps` has already been freed. Honestly, I am a bit lost here. Also I have realized that you needed to release the struct from the module going notifier. And there you have only pointer to struct module. The thing is that I do not see similar tricks anywhere else. Well, other users are easier because they create the debugfs file for it own purpose. In our case, we actually create the file for another module. Anyway, we are going to use the seq_buf iterator API. IMHO, the seq_buf iterator functions should be able to get the structure directly via the data pointer. I wonder if it is similar to proc_seq_open() and proc_seq_release(). It is using the seq_buf iterator as well. It is created used by proc_create_seq_private(). This API is used, for example, in decnet_init(). It is a module, so there must be the similar problems. All data are gone when the module is removed. The only remaining problem is the module going notifier. For this purpose, we could store the pointer to struct module. There are many other fields for similar purposes. I am pretty sure that the module loader maintainer will agree. The result will be using some existing patterns. It should reduce problems with possible races. It should make the life easier for all involved APIs. Best Regards, Petr