Commit Graph

21 Commits

Author SHA1 Message Date
Marek Marczykowski-Górecki
141b9912e8
Initialize pad field in filecopy final response
Do not leak 4 bytes from the receiver stack.

Reported by @cfcs
2017-11-20 13:58:39 +01:00
Rusty Bird
90a1e6abbd
Fall back to sync() if syncfs() is unavailable
It seems better to err on the side of safety (vs. performance).
2017-06-16 16:13:44 +00:00
Paras Chetal
e9b8e5a4d1
Fix include header syntax 2017-06-09 04:45:38 +05:30
Marek Marczykowski-Górecki
410ad3d25f
qrexec-lib: convert tabs to spaces
- Fix compile error on gcc 6 (-Werror=misleading-indentation)
- Follow coding style: https://www.qubes-os.org/doc/coding-style/
2016-06-02 02:32:46 +02:00
Marek Marczykowski-Górecki
c2c36d9c09
qrexec-lib: add glibc version test check for having syncfs
Compile fix for wheezy, which has too old glibc (2.13).
2015-12-11 21:43:40 +01:00
Rusty Bird
4f59b3df6f
qfile-unpacker: syncfs() to avoid qvm-move-to-vm data loss
Commit https://github.com/QubesOS/qubes-linux-utils/commit/c1d42f1 --
"qfile-unpacker: do not call fdatasync() at each file" fixing
QubesOS/qubes-issues#1257 -- increased the chance of data loss with
qvm-move-to-vm: Say it nominally succeeds, and *deletes* the files from
the source VM. Soon after, the destination VM or the system could crash,
or an external drive hosting ~/QubesIncoming/srcVM could get unplugged
by accident, all before the data had really been persisted to disk.

But reverting the commit (ignoring the performance issue) wouldn't
completely solve this:

  "Calling fsync() does not necessarily ensure that the entry in the
   directory containing the file has also reached disk. For that an
   explicit fsync() on a file descriptor for the directory is also
   needed."  - fsync(2)

It gets even worse for "slow symlinks" (whose target is too long to be
stored directly in the inode metadata), apparently they can't be synced
at all individually.

So instead, just call syncfs() once after everything has been unpacked:

  + Should prevent all data loss (if fs and disk are well behaved)
  + Allows caching and reordering -> no slowdown with many small files
  - Blocks until any unrelated writes on the filesystem finish :\
2015-11-18 13:11:30 +00:00
Rusty Bird
74a1b4cc50
Check if QubesIncoming filesystem supports O_TMPFILE
The filesystem hosting ~/QubesIncoming/srcVM/ needs to support O_TMPFILE
too, in addition to the kernel. If it doesn't, take the use_tmpfile = 0
fallback.
2015-11-11 11:35:16 +00:00
Marek Marczykowski-Górecki
c1d42f1602
qfile-unpacker: do not call fdatasync() at each file (#1257)
POSIX  requires  that  a  read(2)  which  can be proved to occur after a
write() has returned returns the new data.
We want here only that other processes in the same VM will see the
file either fully written, or not see it at all. So ensuring that
linkat(2) is called after write is completed should be enough.

Fixes QubesOS/qubes-issues#1257
2015-10-11 02:47:32 +02:00
Marek Marczykowski-Górecki
d5c0761da5 debian: O_TMPFILE already defined 2015-02-17 13:15:32 +01:00
Marek Marczykowski-Górecki
fcbe0363d0 filecopy: fix handling ENOENT error
Do not fail when file was successfully created.

I will test before commit. I will test before commit. I will...
2015-01-30 00:55:46 +01:00
Marek Marczykowski-Górecki
7607b45eae filecopy: really do not use O_TMPFILE when use_tmpfile==0
When file opened with O_TMPFILE but use_tmpfile==0, the file will not be
linked to the directory (the code at the end of process_one_file_reg).
Additionally it is waste of time trying using O_TMPFILE when it's
already known it shouldn't be.
Also use_tmpfile==0 can mean we don't have access to /proc
(set_procfs_fd wasn't called), so even if linking the file to its
directory would be attempted, it would fail. This is the case for
dom0-updates copy.
2015-01-30 00:55:46 +01:00
Marek Marczykowski-Górecki
b0fe4d5868 filecopy: create new file unaccessible to the user until fully written
Otherwise source domain can modify (append) the file while the user
already is accessing it. While incoming files should be treated as
untrusted, this problem could allow file modification after the user
makes some sanity checks.
2015-01-30 00:55:46 +01:00
Marek Marczykowski-Górecki
12a9049cfe Fix some more -Wextra warnings 2014-02-16 11:10:31 +01:00
Vincent Penquerc'h
9f3a74fd77 unpack: prevent ability to bypass the byte limit
By passing an empty file with a declared negative size,
a hostile VM can decrease the total bytes counter, while
not have do supply a huge amount of data, thus disabing
the byte size check, and potentially filling the target
filesystem.
2014-02-15 14:14:20 +01:00
Vincent Penquerc'h
3a39c65e3e linux-utils: misc const/prototype fixups 2014-01-06 14:40:57 +01:00
Vincent Penquerc'h
af78e8d9e8 unpack: count directory and symlink sizes
Also do not rely on unpack being called just once if we don't
have to and initialize counts.

Since we don't know directory size before populating with files,
we just accumulate the size on the second pass, but do not actually
check for the limit being reached. If there's any file after that,
that'll trip the check.
2014-01-06 14:40:57 +01:00
Marek Marczykowski-Górecki
21612bfadf qrexec-lib: add support for verbose mode (echo just processed file) 2013-11-13 10:35:47 +01:00
Marek Marczykowski-Górecki
761305bc8b qrexec-lib: check files limit before processing the file
Off-by-one error.
2013-11-13 10:35:23 +01:00
Marek Marczykowski-Górecki
a73be3f126 qubes-rpc/filecopy: send last processed filename for diagnostic purposes
This will ease solving transfer problems - sender will known at which
file it failed.
2013-08-14 21:28:50 +02:00
Marek Marczykowski-Górecki
138d7899d9 Remove duplicated filecopy.h header
The same also exists as libqubes-rpc-filecopy.h.
2013-08-14 21:25:30 +02:00
Marek Marczykowski
42e133b753 Qrexec common code, qubes.Filecopy common code, udev scripts 2013-03-20 06:27:32 +01:00