mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: barebox@lists.infradead.org, Adrian Negreanu <adrian.negreanu@nxp.com>
Subject: Re: [PATCH 05/11] fs: add qemu_fw_cfg file system
Date: Mon, 17 Mar 2025 09:21:16 +0100	[thread overview]
Message-ID: <Z9fbfE-1IZr44IUs@pengutronix.de> (raw)
In-Reply-To: <20250313101728.3546902-6-a.fatoum@pengutronix.de>

Hi Ahmad,

On Thu, Mar 13, 2025 at 11:17:22AM +0100, Ahmad Fatoum wrote:
> +static int fw_cfg_fs_io(struct device *dev, struct file *f, void *buf,
> +			 size_t insize, bool read)
> +{
> +	struct inode *inode = f->f_inode;
> +	struct fw_cfg_fs_inode *node = inode_to_node(inode);
> +	struct fw_cfg_fs_data *data = dev->priv;
> +	int fd = data->fd;
> +
> +	if (node->buf) {
> +		if (read)
> +			memcpy(buf, node->buf + f->f_pos, insize);
> +		else
> +			memcpy(node->buf + f->f_pos, buf, insize);
> +		return insize;
> +	}
> +
> +	ioctl(fd, FW_CFG_SELECT, &(u16) { inode->i_ino });
> +
> +	if (read)
> +		return pread(fd, buf, insize, f->f_pos);
> +	else
> +		return pwrite(fd, buf, insize, f->f_pos);
> +}
> +
> +static int fw_cfg_fs_read(struct device *dev, struct file *f, void *buf,
> +			   size_t insize)
> +{
> +	return fw_cfg_fs_io(dev, f, buf, insize, true);
> +}
> +
> +static int fw_cfg_fs_write(struct device *dev, struct file *f, const void *buf,
> +			    size_t insize)
> +{
> +	return fw_cfg_fs_io(dev, f, (void *)buf, insize, false);
> +}
> +
> +static int fw_cfg_fw_truncate(struct device *dev, struct file *f, loff_t size)
> +{
> +	return 0;
> +}

By returning 0 here you claim that the file can get an arbitrary size.

node->buf is a fixed size buffer. If I understand correctly then
node->buf is only used for special files like "name", "raw".

However, writing to these files is not prohibited, consequently a
cp /dev/ram0 /mnt/fw_cfg//by_key/37/key results in memory corrupions.

Writing data to a file I passed via --env truncates the file to the
written data size, but the actual content of the file is unchanged. I
still read back the original data. Is writing data supported?

Sascha

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |



  reply	other threads:[~2025-03-17  8:23 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13 10:17 [PATCH 00/11] firmware: qemu_fw_cfg: implement " Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 01/11] video: ramfb: fix frame buffer screen size Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 02/11] firmware: qemu_fw_cfg: drop duplicate definitions Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 03/11] firmware: qemu_fw_cfg: add support for seeking Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 04/11] firmware: qemu_fw_cfg: rename from /dev/fw_cfg0 to /dev/fw_cfg Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 05/11] fs: add qemu_fw_cfg file system Ahmad Fatoum
2025-03-17  8:21   ` Sascha Hauer [this message]
2025-03-17 11:34     ` Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 06/11] firmware: qemu_fw_cfg: register at device initcall level Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 07/11] video: ramfb: use new qemu fw_cfg FS Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 08/11] libfile: give copy_file a flags parameter Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 09/11] libfile: pass copy_file flags through copy_recursive Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 10/11] libfile: add support for not clobbering files in copy_file Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 11/11] fs: qemu_fw_cfg: support populating environment via QEMU fw_cfg Ahmad Fatoum
2025-03-17  7:44   ` Sascha Hauer
2025-03-17 11:36     ` Ahmad Fatoum

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=Z9fbfE-1IZr44IUs@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=a.fatoum@pengutronix.de \
    --cc=adrian.negreanu@nxp.com \
    --cc=barebox@lists.infradead.org \
    /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