RE: Splicing to/from a tty

From: David Laight
Date: Thu Jan 21 2021 - 05:11:55 EST


From: Linus Torvalds
> Sent: 21 January 2021 01:04
> On Wed, Jan 20, 2021 at 4:38 PM Al Viro <viro@xxxxxxxxxxxxxxxxxx> wrote:
> >
> > OK... I wonder how many debugfs writable files allow pwrite() with
> > BS results...
>
> I hope some of them check for "pos == 0" when they start parsing integers.
>
> But honestly, I don't think it's a big deal. We've had these things
> that just basically assume that whenever you write, the offset just
> doesn't matter at all, and as long as some number comes in one single
> write call, we accept it.
>
> Because even if you end up doing something like just
>
> echo $SOMETHING > /sys/xyz/abc
>
> and that "$SOMETHING" could be done multiple writes, in practice it
> all works out just fine and it never really is. You almost have to try
> to screw up with something like
>
> (echo -n 3; echo -n 4) > /sys/xyz/abc
>
> to actually see two writes of "3" and "4" instead of one write with
> "34". And honestly, if somebody does something like that, do we really
> care? They might get 3, they might get 4, and they might get 34. They
> get what they deserve.

Or worse:
echo abc >/sys/xyz/abc
echo x | dd bs=1 count=2 oseek=1 conv=notrunc of=/sys/xyz/abc
which (if I got the dd command right) would generate "axc" on a real file.

OTOH multiple short reads are quite likely.
Best not done on a counter...

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)