summaryrefslogtreecommitdiffstats
path: root/common/console.c
diff options
context:
space:
mode:
authorAhmad Fatoum <ahmad@a3f.at>2019-09-20 09:58:10 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2019-10-14 12:52:11 +0200
commit3e51bdfd2c31e1f3bdb3a65f6480950ba360b8e6 (patch)
treed59612e6bf9531d47c2bb6fd1da1bacb4d7731ff /common/console.c
parentd1210dc63f38e7e6d8147b44b3f6f9518c099306 (diff)
downloadbarebox-3e51bdfd2c31e1f3bdb3a65f6480950ba360b8e6.tar.gz
console: disallow opening for writing when no write method defined
Some consoles, like the input console (usually /dev/cs0), don't feature a puts or putc callback. Trying to echo out of them would thus crash: barebox@Embest MarS Board i.MX6Dual:/ echo -a /dev/cs0 prefetch abort pc : [<00000004>] lr : [<4fd05071>] WARNING: [<...>] (fops_write+0xd/0x10) WARNING: [<...>] (devfs_write+0x21/0x2a) WARNING: [<...>] (__write+0xcb/0xf0) WARNING: [<...>] (write+0x2d/0x68) WARNING: [<...>] (dputc+0x31/0x34) WARNING: [<...>] (do_echo+0xcb/0x144) Fix this by only allowing open(.., O_WRONLY) or open(..., O_RDWR) when puts is defined. Consoles defining putc are covered by this as well as those have putc-calling __console_puts assigned as their puts when they are registered. Now echo -a /dev/cs0 would yield: open: Operation not permitted Signed-off-by: Ahmad Fatoum <ahmad@a3f.at> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/common/console.c b/common/console.c
index d04aae5..e6e0298 100644
--- a/common/console.c
+++ b/common/console.c
@@ -272,6 +272,9 @@ static int fops_open(struct cdev *cdev, unsigned long flags)
{
struct console_device *priv = cdev->priv;
+ if ((flags & (O_WRONLY | O_RDWR)) && !priv->puts )
+ return -EPERM;
+
return console_open(priv);
}