From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: uol@pengutronix.de, ske@pengutronix.de,
Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH master 2/3] fs: devfs: restore cdev reference count maintenance
Date: Wed, 15 May 2024 10:05:06 +0200 [thread overview]
Message-ID: <20240515080507.4056255-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20240515080507.4056255-1-a.fatoum@pengutronix.de>
barebox v2024.03.0 moves the reference count maintenance into
cdev_open/cdev_close, but missed to switch devfs_open and devfs_close to
actually use cdev_open/cdev_close. The result was that the cdev could be
deleted, e.g. due to partition reparsing, and further use of the file
descriptor would result in a use-after-free.
Fix this by doing what the commit introducing the breakage was purported
to do.
Fixes: d84c3daf1314 ("fs: move cdev open count to cdev_open()/cdev_close()")
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/devfs.c | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/fs/devfs.c b/fs/devfs.c
index c8ddbbdab04d..f5bad5aa9bf2 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -102,33 +102,19 @@ static int devfs_open(struct device *_dev, FILE *f, const char *filename)
struct inode *inode = f->f_inode;
struct devfs_inode *node = container_of(inode, struct devfs_inode, inode);
struct cdev *cdev = node->cdev;
- int ret;
f->size = cdev->flags & DEVFS_IS_CHARACTER_DEV ?
FILE_SIZE_STREAM : cdev->size;
f->priv = cdev;
- if (cdev->ops->open) {
- ret = cdev->ops->open(cdev, f->flags);
- if (ret)
- return ret;
- }
-
- return 0;
+ return cdev_open(cdev, f->flags);
}
static int devfs_close(struct device *_dev, FILE *f)
{
struct cdev *cdev = f->priv;
- int ret;
- if (cdev->ops->close) {
- ret = cdev->ops->close(cdev);
- if (ret)
- return ret;
- }
-
- return 0;
+ return cdev_close(cdev);
}
static int devfs_flush(struct device *_dev, FILE *f)
--
2.39.2
next prev parent reply other threads:[~2024-05-15 8:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-15 8:05 [PATCH master 1/3] cdev: return error code from cdev_close Ahmad Fatoum
2024-05-15 8:05 ` Ahmad Fatoum [this message]
2024-05-15 8:05 ` [PATCH master 3/3] partition: reparse tables only if CONFIG_PARTITION_MANIPULATION=y Ahmad Fatoum
2024-05-15 9:24 ` [PATCH] fixup! " Ahmad Fatoum
2024-05-16 7:13 ` [PATCH master 1/3] cdev: return error code from cdev_close Sascha Hauer
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=20240515080507.4056255-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=ske@pengutronix.de \
--cc=uol@pengutronix.de \
/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