[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH] lib/vfscore: vfscore_put_fd: do not reject fd <= 2



Rejecting fd <= 2 is legitimate in some way, since freeing std(in|out|err)
might lead to crash if .f_count is 1. This is because stdin, stdout and stderr
fps are statically allocated.  However, returning -EBUSY in this case breaks
dup2 with stdin, out, and err.  Ignoring this should be fine as long as those
are not fdrop-ed twice.

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@xxxxxxxxx>
---
 lib/vfscore/fd.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/vfscore/fd.c b/lib/vfscore/fd.c
index 6b7f5ec..684ea50 100644
--- a/lib/vfscore/fd.c
+++ b/lib/vfscore/fd.c
@@ -97,9 +97,15 @@ int vfscore_put_fd(int fd)
        unsigned long flags;
 
        UK_ASSERT(fd < (int) FDTABLE_MAX_FILES);
-       /* Currently it is not allowed to free std(in|out|err) */
-       if (fd <= 2)
-               return -EBUSY;
+
+       /* FIXME Currently it is not allowed to free std(in|out|err):
+        * if (fd <= 2) return -EBUSY;
+        *
+        * However, returning -EBUSY in this case breaks dup2 with stdin, out,
+        * err. Ignoring this should be fine as long as those are not fdrop-ed
+        * twice, in which case the static fp would be freed, and here be
+        * dragons.
+        */
 
        flags = ukplat_lcpu_save_irqf();
        uk_bitmap_clear(fdtable.bitmap, fd, 1);
-- 
2.7.4


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.