From: Tong Zhang <ztong0001@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jakub Kicinski <kuba@kernel.org>,
Colin Ian King <colin.king@intel.com>,
Saurav Girepunje <saurav.girepunje@gmail.com>,
Nathan Chancellor <nathan@kernel.org>,
Johan Hovold <johan@kernel.org>,
open list <linux-kernel@vger.kernel.org>,
linux-staging@lists.linux.dev,
Dan Carpenter <dan.carpenter@oracle.com>
Subject: Re: [PATCH v2 2/3] staging: rtl8192u: move debug files to debugfs
Date: Tue, 19 Jul 2022 21:58:24 -0700 [thread overview]
Message-ID: <CAA5qM4B9p05KLFhsmcbYud65dUHPXqETc7rFqer0pNLjH_mJpA@mail.gmail.com> (raw)
In-Reply-To: <YtalnN70xXy3PNNN@kroah.com>
On Tue, Jul 19, 2022 at 5:53 AM Greg Kroah-Hartman
<gregkh@linuxfoundation.org> wrote:
>
> On Mon, Jul 18, 2022 at 10:50:37PM -0700, Tong Zhang wrote:
> > There are 4 debug files created under /proc/net/[Devname]. Devname could
> > Due to this is purely for debuging as files are created read only,
> > move this to debugfs like other NIC drivers do instead of using procfs.
> > This is also to prepare for address rmmod warn issue.
>
> Minor comments based on good debugfs usage:
>
> > --- a/drivers/staging/rtl8192u/r8192U.h
> > +++ b/drivers/staging/rtl8192u/r8192U.h
> > @@ -1061,6 +1061,9 @@ typedef struct r8192_priv {
> > struct delayed_work gpio_change_rf_wq;
> > struct delayed_work initialgain_operate_wq;
> > struct workqueue_struct *priv_wq;
> > +
> > + /* debugfs */
> > + struct dentry *debugfs_dir;
>
> Why do you need to save this dentry? Can't you just look it up when you
> want to remove the files?
>
Hi Greg,
Thanks for the comments.
I am thinking whether it is possible to rename the device and run
rmmod to remove something it shouldn't.
If we are using debugfs_lookup(dev->name, NULL), say, the existing
directories/files are
/sys/kernel/debug/DIRA
/sys/kernel/debug/wlan0
I then rename device wlan0 to DIRA, after that I remove the module by
doing rmmod.
Apparently either the wlan0 directory will not be renamed successfully
due to collision or DIRA directory might be overwritten? (this part I
haven't checked yet)
Either Way, later on if we do rmmod, the driver will try to do
debugfs_lookup("fileA", NULL) and remove /sys/kernel/debug/DIRA which
it shouldn't.
Or if it is possible to rename the device to some wacky string
containing wildcard or .. to launch an attack.
Maybe I am being naive but please correct me if I am wrong.
Or maybe we should put those debug files under the module's own
directory and do lookup from there instead. like the following dir
structure
/sys/kernel/debug/r8192u_usb/wlan0/stats-rx
/sys/kernel/debug/r8192u_usb/wlan0/stats-rx
/sys/kernel/debug/r8192u_usb/wlan0/stats-ap
/sys/kernel/debug/r8192u_usb/wlan0/registers
> > +void rtl8192_debugfs_init(struct net_device *dev)
> > {
> > - struct proc_dir_entry *dir;
> > + struct dentry *dir;
> > + struct r8192_priv *priv = (struct r8192_priv *)ieee80211_priv(dev);
>
> No need to cast this. Same for later on in this file.
>
agreed, will remove those redundant checks.
> > - if (!rtl8192_proc)
> > + dir = debugfs_create_dir(dev->name, NULL);
> > + if (IS_ERR(dir))
> > return;
>
> No need to check, just keep moving on.
>
> >
> > - dir = proc_mkdir_data(dev->name, 0, rtl8192_proc, dev);
> > - if (!dir)
> > - return;
> > + debugfs_create_file("stats-rx", 0444, dir, dev, &rtl8192_usb_stats_rx_fops);
> > + debugfs_create_file("stats-tx", 0444, dir, dev, &rtl8192_usb_stats_tx_fops);
> > + debugfs_create_file("stats-ap", 0444, dir, dev, &rtl8192_usb_stats_ap_fops);
> > + debugfs_create_file("registers", 0444, dir, dev, &rtl8192_usb_registers_fops);
> >
> > - proc_create_single("stats-rx", S_IFREG | 0444, dir,
> > - proc_get_stats_rx);
> > - proc_create_single("stats-tx", S_IFREG | 0444, dir,
> > - proc_get_stats_tx);
> > - proc_create_single("stats-ap", S_IFREG | 0444, dir,
> > - proc_get_stats_ap);
> > - proc_create_single("registers", S_IFREG | 0444, dir,
> > - proc_get_registers);
> > + priv->debugfs_dir = dir;
>
> Again, no need to save this, just look it up when removing the
> directory.
>
> thanks,
>
> greg k-h
Thanks and have a good one!
- Tong
next prev parent reply other threads:[~2022-07-20 4:58 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-16 12:16 [BUG] staging: rtl8192u: Found a bug when removing the module Zheyu Ma
2022-07-17 7:01 ` Tong Zhang
2022-07-17 7:01 ` [PATCH] staging: rtl8192u: fix rmmod warn when wlan0 is renamed Tong Zhang
2022-07-17 8:04 ` Zheyu Ma
2022-07-18 11:39 ` Dan Carpenter
2022-07-18 11:47 ` Dan Carpenter
2022-07-18 12:01 ` Dan Carpenter
2022-07-19 5:50 ` [PATCH v2 0/3] " Tong Zhang
2022-07-19 8:04 ` Dan Carpenter
2022-07-19 5:50 ` [PATCH v2 1/3] staging: rtl8192u: move debug stuff to its own file Tong Zhang
2022-07-19 5:50 ` [PATCH v2 2/3] staging: rtl8192u: move debug files to debugfs Tong Zhang
2022-07-19 12:37 ` Greg Kroah-Hartman
2022-07-20 4:58 ` Tong Zhang [this message]
2022-07-27 6:35 ` Greg Kroah-Hartman
2022-07-20 6:30 ` Tong Zhang
2022-07-27 6:37 ` Greg Kroah-Hartman
2022-07-29 3:51 ` Tong Zhang
2022-07-29 3:52 ` [PATCH v3 0/3] staging: rtl8192u: fix rmmod warn when device is renamed Tong Zhang
2022-07-29 3:52 ` [PATCH v3 1/3] staging: rtl8192u: move debug stuff to its own file Tong Zhang
2022-07-29 6:23 ` Philipp Hortmann
2022-07-30 3:35 ` Tong Zhang
2022-07-29 3:52 ` [PATCH v3 2/3] staging: rtl8192u: move debug files to debugfs Tong Zhang
2022-07-29 7:31 ` Greg Kroah-Hartman
2022-07-29 3:52 ` [PATCH v3 3/3] staging: rtl8192u: fix rmmod warn when device is renamed Tong Zhang
2022-07-29 7:27 ` Greg Kroah-Hartman
2022-07-30 3:33 ` Tong Zhang
2022-07-30 3:33 ` [PATCH v4 0/4] " Tong Zhang
2022-07-30 3:33 ` [PATCH v4 1/4] staging: rtl8192u: move debug stuff to its own file Tong Zhang
2022-07-30 3:33 ` [PATCH v4 2/4] staging: rtl8192u: remove unnecessary cast Tong Zhang
2022-07-30 3:33 ` [PATCH v4 3/4] staging: rtl8192u: move debug files to debugfs Tong Zhang
2022-07-30 3:33 ` [PATCH v4 4/4] staging: rtl8192u: fix rmmod warn when device is renamed Tong Zhang
2022-07-19 5:50 ` [PATCH v2 3/3] staging: rtl8192u: fix rmmod warn when wlan0 " Tong Zhang
2022-07-19 12:39 ` Greg Kroah-Hartman
2022-07-20 6:16 ` Tong Zhang
2022-07-19 5:52 ` [PATCH] " Tong Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAA5qM4B9p05KLFhsmcbYud65dUHPXqETc7rFqer0pNLjH_mJpA@mail.gmail.com \
--to=ztong0001@gmail.com \
--cc=colin.king@intel.com \
--cc=dan.carpenter@oracle.com \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-staging@lists.linux.dev \
--cc=nathan@kernel.org \
--cc=saurav.girepunje@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).