Received: by 2002:a05:7412:6592:b0:d7:7d3a:4fe2 with SMTP id m18csp1508635rdg; Sat, 12 Aug 2023 04:27:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH1NulvegRymVltkdERKMUbJMe9a5o+Oh8jPcmC3k43UMBbTEsmQnC6/eBCZZSSR1BjlVp1 X-Received: by 2002:a17:906:8458:b0:957:1df0:9cbf with SMTP id e24-20020a170906845800b009571df09cbfmr3848244ejy.19.1691839674968; Sat, 12 Aug 2023 04:27:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691839674; cv=none; d=google.com; s=arc-20160816; b=mNqv4ZYyRt11Fv8Wid50PSjyASrDh9IYA6OOakKj2laXfNYBmAUgsVglOqXOt0/wEo o67Z728/coXIGNFOFJm6BtiE2MUq59F4yPKXl8D2Z0lmlfYkmLIMKV5y1iSp1P2SNyvE guFqGzctVKJbBHhJAhFE2UN9MOcUjNv6CY1AZNy8tj2fLpvry4pzAHD8WZHsM0QqsybZ 2MNSGeyaxhJVAsKhD18VUS0VLCL4ONBmssGIrTxqgqM+hbL/r8TcY6eo6V/zO1LS01Wd QzJ467+iW87jLFSzIleHWH3AO3KwC+WEzUp/Kw+/BSK4fzNeOMg0R/Df9DGRT1PDLAqy s5EA== 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=XILJcrlvtEF+42/AhL5IFRo2RiYGteOmfDp8QCjSCpo=; fh=JqmZvI0TVjITxS2QvWC8bDy2da+q23p8jgexqHm5lwo=; b=stzaJHrWqneF943SLTlqo6Bt4RfPND1I60wDb2uQp/kKHTm+zS9CsmB4uIF+txBlFO jvytRY/viDMbhjySx/4Gu3pdrP8puxGiXACIe1Ht2sMm795TL7+4x+lbri0Mi+2sUAj3 e+g+KRaZVDrad6Jint6E7VSU2b09CUOjV6hGzIkhIf97DlP9O2l/T8ar22LRR7VAltD8 WsSFapgsaYc+2TsfA45Z0pTTtjX3XUCd5IsW3FKAPl4hRTXzX4C2/GsN9Awp7RG7lSlW xwn/ejn7IoqzOw1OK7iNGJSRNYgOCNG2cX7Js+Ji8q+mLngV+lrxRmhJX7Z3MI9mj4Xh HSJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=pRmRKXiO; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ss22-20020a170907039600b0099381745ba0si5480958ejb.156.2023.08.12.04.27.29; Sat, 12 Aug 2023 04:27:54 -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=@linuxfoundation.org header.s=korg header.b=pRmRKXiO; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236047AbjHLKkD (ORCPT + 99 others); Sat, 12 Aug 2023 06:40:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjHLKkB (ORCPT ); Sat, 12 Aug 2023 06:40:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D32D1720; Sat, 12 Aug 2023 03:40:04 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2629B60C36; Sat, 12 Aug 2023 10:40:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0118C433C7; Sat, 12 Aug 2023 10:40:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1691836803; bh=FFptfCtf+waW/3p6NKc2ompsRkv2J2bQvCJ3CBn2rCU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pRmRKXiOVfml49KX2SPH4faT6O7B3g+bksu0JLFhLDF2HU365jAMatz6CWE/virlY 29YeDfhsGZIsiJj2vHPO6KuEh1tiyw6mkJwo9oqS4PDjouw/TWkJXEaQXklHgdvyEd Wwqk3ULNn8BZnDtBm4K28HYMw9m5V0vFAclkSM6o= Date: Sat, 12 Aug 2023 12:40:00 +0200 From: Greg KH To: Mike Tipton Cc: djakov@kernel.org, rafael@kernel.org, corbet@lwn.net, linux-pm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, quic_okukatla@quicinc.com, quic_viveka@quicinc.com, peterz@infradead.org, quic_pkondeti@quicinc.com Subject: Re: [PATCH v3 1/3] debugfs: Add write support to debugfs_create_str() Message-ID: <2023081203-happier-mutable-e4f0@gregkh> References: <20230807142914.12480-1-quic_mdtipton@quicinc.com> <20230807142914.12480-2-quic_mdtipton@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230807142914.12480-2-quic_mdtipton@quicinc.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,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 Mon, Aug 07, 2023 at 07:29:12AM -0700, Mike Tipton wrote: > Currently, debugfs_create_str() only supports reading strings from > debugfs. Add support for writing them as well. > > Based on original implementation by Peter Zijlstra [0]. Write support > was present in the initial patch version, but dropped in v2 due to lack > of users. We have a user now, so reintroduce it. > > [0] https://lore.kernel.org/all/YF3Hv5zXb%2F6lauzs@hirez.programming.kicks-ass.net/ > > Signed-off-by: Mike Tipton > --- > fs/debugfs/file.c | 48 +++++++++++++++++++++++++++++++++++++++++++++-- > 1 file changed, 46 insertions(+), 2 deletions(-) > > diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c > index b7711888dd17..87b3753aa4b1 100644 > --- a/fs/debugfs/file.c > +++ b/fs/debugfs/file.c > @@ -904,8 +904,52 @@ EXPORT_SYMBOL_GPL(debugfs_create_str); > static ssize_t debugfs_write_file_str(struct file *file, const char __user *user_buf, > size_t count, loff_t *ppos) > { > - /* This is really only for read-only strings */ > - return -EINVAL; > + struct dentry *dentry = F_DENTRY(file); > + char *old, *new = NULL; > + int pos = *ppos; > + int r; > + > + r = debugfs_file_get(dentry); > + if (unlikely(r)) > + return r; > + > + old = *(char **)file->private_data; > + > + /* only allow strict concatenation */ > + r = -EINVAL; > + if (pos && pos != strlen(old)) > + goto error; > + > + r = -E2BIG; > + if (pos + count + 1 > PAGE_SIZE) > + goto error; > + > + r = -ENOMEM; > + new = kmalloc(pos + count + 1, GFP_KERNEL); > + if (!new) > + goto error; > + > + if (pos) > + memcpy(new, old, pos); > + > + r = -EFAULT; > + if (copy_from_user(new + pos, user_buf, count)) > + goto error; > + > + new[pos + count] = '\0'; > + strim(new); > + > + rcu_assign_pointer(*(char **)file->private_data, new); > + synchronize_rcu(); > + kfree(old); > + > + debugfs_file_put(dentry); > + return count; > + > +error: > + kfree(new); > + debugfs_file_put(dentry); > + return r; > } So you just added write support for ALL debugfs files that use the string interface, what did you just allow to break? I recommend just using your own debugfs file function instead, as this could cause bad problems, right? Are you sure that all string calls can handle the variable be freed underneath it like this call will allow to happen? So I wouldn't recommend doing this, sorry. greg k-h