Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2605438pxf; Sat, 27 Mar 2021 18:10:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwad23sjd81hXRPFPnK4AVrvdOr12y0Cu+Y0SLxkpJxciFrtwn8XfLsa6E3bcE4YVFE7TVn X-Received: by 2002:a17:906:3f88:: with SMTP id b8mr22855495ejj.36.1616893830981; Sat, 27 Mar 2021 18:10:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616893830; cv=none; d=google.com; s=arc-20160816; b=vtOSDtVujCGOBZdXAe8GzhibtP6cMZl7mJYSO7JIWYgAOkQNCtgavAN8o4ucuCP33H FLnov6zmW2htHQBKBxrKLzxYGU+4KNb37z2hsGcnJUa9V/eut82InFDCmHz/grTt2trN nx9BCzmWRnAt6j+dZe8E4Zudn1MM6ETUYwVzSUzJa0FThHmR7Z1Sw42ypNvOl7d+bn3T BbdIdq9qZVIt+kl5BSb3xUhFXnaf8+S1HmWAoBbIW4bGUEiWXxaHUkelHBtQUueLODJt vfjGsoH6rajd9Ima9rjiiiPSkbQLJaHnNryOhsXR8n2kUpCJVFUhPQPE+YRnfdlPj/By zVqw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=2O6HzT0ULssYknHWLqUr7pQcXRUc6kcEi28m4U3ebUM=; b=IjU7jazmsRHdH1Pq7C10lmsnRlpotBG93RQbn+QEdSQSpzrjbI9pIXJ3gSrshWgOs8 i9Hc9dB5w7DdbWaX6rquCtodC+pFhnP3Ppq32Trt7Oi5OLK9Vi1gbHNF3gcRd7Ou198L T7SdFk1TCMgSOAZZ0o2ryAKr49/fsRhvJAr+TA8Kh6cw2R7jA4HPZYYG2IrTQehh7B7V K+MPlySNsS9mv/dGgOnSQt++iSKr3b94JLI/QFpXB4ht5NnTAagelGYv12tWiE5WGM7F s+vNzS3GA+zezmR6225mevIDUMozo4+gkzz4yCgGhcdZYaSq+l9Sg4wmB4YYNlaE7AAM FTeg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c11si10367802edr.72.2021.03.27.18.09.25; Sat, 27 Mar 2021 18:10:30 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230470AbhC1Ade (ORCPT + 99 others); Sat, 27 Mar 2021 20:33:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:57132 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230384AbhC1AdS (ORCPT ); Sat, 27 Mar 2021 20:33:18 -0400 Received: from oasis.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DC9C061993; Sun, 28 Mar 2021 00:33:16 +0000 (UTC) Date: Sat, 27 Mar 2021 20:33:15 -0400 From: Steven Rostedt To: Al Viro Cc: Peter Zijlstra , mingo@kernel.org, mgorman@suse.de, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, bsegall@google.com, bristot@redhat.com, joshdon@google.com, valentin.schneider@arm.com, linux-kernel@vger.kernel.org, greg@kroah.com Subject: Re: [PATCH 6/9] debugfs: Implement debugfs_create_str() Message-ID: <20210327203315.3cd7bcda@oasis.local.home> In-Reply-To: References: <20210326103352.603456266@infradead.org> <20210326103935.183934395@infradead.org> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, 27 Mar 2021 22:24:45 +0000 Al Viro wrote: > On Fri, Mar 26, 2021 at 11:33:58AM +0100, Peter Zijlstra wrote: > > > +again: > > + rcu_read_lock(); > > + str = rcu_dereference(*(char **)file->private_data); > > + len = strlen(str) + 1; > > + > > + if (!copy || copy_len < len) { > > + rcu_read_unlock(); > > + kfree(copy); > > + copy = kmalloc(len + 1, GFP_KERNEL); > > + if (!copy) { > > + debugfs_file_put(dentry); > > + return -ENOMEM; > > + } > > + copy_len = len; > > + goto again; > > + } > > + > > + strncpy(copy, str, len); > > + copy[len] = '\n'; > > + copy[len+1] = '\0'; > > + rcu_read_unlock(); > > *Ow* > > If the string can't change under you, what is RCU use about? > And if it can, any use of string functions is asking for serious > trouble; they are *not* guaranteed to be safe when any of the strings > involved might be modified under them. Just from looking at the above, RCU isn't protecting that the string can change under you, but the pointer to file->private_data can. str = rcu_dereference(*(char **)file->private_data); That's just getting a pointer to the string. While under rcu, the value of that string wont change nor will it be free. But file->private_data might change, and it might free its old value, but will do so after a RCU grace period (which is why the above has rcu_read_lock). What the above looks like to me is a way to copy that string safely, without worrying that it will be freed underneath you. But there's no worry that it will change. -- Steve