Hi Sava,
On 19.02.21 17:59, Sava Jakovljev wrote:
> Hello,
>
> Just to provide a way that represents better what is the concern and why
> this is a leak in my opinion, even though sockets are saved in swupdate
> code:
> I ran a script which calls swupdate-progress in an infinite loop, waits
> for short period of time, then exits swupdate-progress and continue the
> loop.
It is not a mistery what it happens...
> After few minutes swupdate has more than 1024 open fd's.
Nothing else expected.
> This is clearly
> a bug - why shouldn't we check for dead connections when accepting a new
> one?
You have just proofed that your application (the test script) is a mess
- please consider that the progress interface is a *LOCAL* interface
based on UDS, and it is not open to the world. It is duty of the
integrator to build a suitable system, that is to estimate how many
progress client should be started and sets accordingly rights to the
sockets to avoid local exploits.
> As a consequence, command IPC is not working anymore
Of course
> - Linux forbids
> swupdate to open any new file
according to limits and/or cgroups, and it is a good thing.
> - it doesn't matter at all that progress
> IPC and command IPC are separated, they are part of the same process -
> so I don't think this is out of context or that I am mixing any terms.
> From Linux point of view, a process is simply exceeding maximum number
> of open files so it won't allow it to take any more.
Exactly. But it is not that it is possible to generate any mess on the
device and then try to fix somewhere else. I could also randomly write
into /dev/mem and then complying that something crashes..
>
> Waiting for swupdate to send a message to progress IPC to clear them up
> is not a good solution, in my opinion.
The correct way to check if a connection is still alive is to use the
connection, that is sending / receiving or using the KEEP_ALIVE option.
But as this is a UDS, keep alive is not available and it cannot be
replaced by a message at the application level (in SWUpdate, then),
because the progress interface is thought to be unidirectional (no ACK
on the other side).
> Giving that swupdate is a background process which sits idle most of the
> time and that progress IPC is only sent when there is an upgrade,
> clearing dangling fd's point when message is actually sent, which is
> not often, and worse, when upgrade status is changed, is unacceptable,
> IMHO.
Agree, but what is unacceptable is to force this to a private and local
interface, that is for definition unprotected.
> I'm just trying to be clear here, that swupdate should be robust
> and stable regardless of buggy clients which could spawn many
> re-connections.
Where are the buggy clients ? If we are talking about clients connecting
through internet and try to force a DOS, fully agree. But if crappy
clients are implemented and put on the device, this is not duty of
SWUpdate. If any program can be executed, then socket's access must be
protected.
> Having "Too many open files" error is not what I would
> expect from an upgrade service in any scenario.
I can break any device if I can run what I want on it.
>
> Regarding my implementation of the check, we can use getsockopt with
> SOL_SOCKET if you prefer that better,
I guess this does not work - getsockopt just returns the last error if
this happened. That means, after doing something on the socket, that is
by reading (but not available here as the socket is just to send), or by
writing (as it is already done). If you call getsockopt(sock,
SOL_ERROR...) without any operation, there is no error at all.
> and if you agree with my reasoning
> - if I am making an error here, please let me know.
If SWUpdate should monitor the client connections, a keep alive
mechanism is necessary. Linux's keepalive does not work for UDS, so this
should be added in SWUpdate, and the thread should send periodically
messages to the client (messages that should be discarded by the client)
to verify the connection
Best regards,
Stefano Babic
>
https://groups.google.com/d/msgid/swupdate/e6f35507-db00-460b-b3cb-4a136c24ee65n%40googlegroups.com
> <
https://groups.google.com/d/msgid/swupdate/e6f35507-db00-460b-b3cb-4a136c24ee65n%40googlegroups.com?utm_medium=email&utm_source=footer>.