-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Mpr/fix rm remote #17149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mpr/fix rm remote #17149
Conversation
Code size report:
|
The code seems like a correct implementation of the stated feature -- in that it gates this behind There should only be a single source of truth for what that path's name is. Even if it's ultimately still a hardcoded string, it should be one string in one place -- not a first copy of that string in the code setting up the mount, and a second copy of that string in the rm check. This could be done dynamically using |
I would be more than happy to catch the 98% of cases where the remote vfs is created through mpremote, The current Dual SOT is the
doing an AST parse of that to extract "/remote" would be a bit much IMO, A KISS solution would be to add a |
Either of those seem pretty reasonable to me. |
After some thought, the approach I'd advocate would be to modify def __mount():
global __mount_MOUNTPOINT
__mount_MOUNTPOINT = (RemoteFS(RemoteCommand()), '/remote')
os.mount(*__mount_MOUNTPOINT)
os.chdir(__mount_MOUNTPOINT[1]) Then, for the host-mount check in (Regarding making it a tuple, the idea there is to make it polymorphic with the entries returned by |
Safeguarding this on the command-issuer side feels like a somewhat backwards approach to the problem, though. The unix-like idiom to use for this type of protection would be to bail out with an EROFS 'Read-only file system' error or similar, at the filesystem layer; and with a This error could potentially be triggered on the device side inside the fs hook. To do that, would mean needing to make the presence or absence of @contextlib.contextmanager
def fs_flags_set_on_remote(state, args):
state.transport.exec(f'__mpremote_args={vars(args)!r}')
try:
yield
finally:
state.transport.exec('del __mpremote_args')
with fs_flags_set_on_remote(state, args):
... # actual command functions Then in the class RemoteFS:
...
def _err_if_unforced(err, path):
global __mpremote_args
try:
if __mpremote_args['force'] is False:
raise OSError(err, path)
except NameError:
pass # still allow other programmatic removal
def remove(self, path):
self._err_if_unforced(30, path) # errno.EROFS
...
def rmdir(self, path):
self._err_if_unforced(30, path) # errno.EROFS
... This could also be added to def open(self, path, mode):
if any(flag in mode for flag in 'wxa+'):
self._err_if_unforced(errno.EROFS, path)
... Though, that still wouldn't prevent the truncation issue on the reverse operation (i.e.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #17149 +/- ##
=======================================
Coverage 98.54% 98.54%
=======================================
Files 169 169
Lines 21890 21890
=======================================
Hits 21572 21572
Misses 318 318 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
I'd advocate to keep this change/fix simple, and the PR here is pretty simple. Although eliminating the duplicated
|
7e5b586
to
4b72b8f
Compare
Updated to use |
Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
Removes the risk of inadvertently deleting files on the host by preventing the deletion of files via `rm -r` on the `/remote` vfs mount point. Fixes issue micropython#17147. Signed-off-by: Jos Verlinde <jos_verlinde@hotmail.com>
4b72b8f
to
6406afb
Compare
Summary
Removes the risk of inadvertently deleting files from the host by preventing the deletion of files from the host via
rm -r
on the/remote
vfs as reported in #17147.Testing
The PR adds a test for
rm -r
on the/remote
vfs to ensure that the deletion of files from the host is prevented.Tested manually on Windows.
Trade-offs and Alternatives
The fix only addresses the risk via
rm -r
as that has a potentially large impact, and not with just therm
command that has been in use for quite some time.The same safeguard could be added to the `rm' command.
Fixes: #17147