fstab module is unsafe

Bug #1895619 reported by Paul Collins
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Charm Helpers
New
Undecided
Unassigned

Bug Description

The fstab module does this:

```
class Fstab(io.FileIO):
    # [...]
    def remove_entry(self, entry):
        # [...]
        self.seek(0)
        self.write(''.join(lines).encode('us-ascii'))
        self.truncate()
```

If a crash occurs at the right time, and the write was large enough to be split into multiple operations, or if the crash occurs after write and before truncate, /etc/fstab could have trailing garbage and may be sufficiently damaged so as to cause problems booting.

Instead the file should be always updated using the write-new-file/fsync/rename/fsync pattern.

(Depending on which filesystem developer you're talking to, the weather, and the condition of the Sun's corona, you may be recommended different recipes. But the current methodology is certainly flawed.)

Paul Collins (pjdc)
description: updated
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.