@@ -164,15 +164,16 @@ func prepareRootfs(pipe io.ReadWriter, iConfig *initConfig, mountFds []int) (err
164
164
// finalizeRootfs sets anything to ro if necessary. You must call
165
165
// prepareRootfs first.
166
166
func finalizeRootfs (config * configs.Config ) (err error ) {
167
- // remount dev as ro if specified
167
+ // All tmpfs mounts and /dev were previously mounted as rw
168
+ // by mountPropagate. Remount them read-only as requested.
168
169
for _ , m := range config .Mounts {
169
- if utils .CleanPath (m .Destination ) == "/dev" {
170
- if m .Flags & unix .MS_RDONLY == unix .MS_RDONLY {
171
- if err := remountReadonly (m ); err != nil {
172
- return err
173
- }
170
+ if m .Flags & unix .MS_RDONLY != unix .MS_RDONLY {
171
+ continue
172
+ }
173
+ if m .Device == "tmpfs" || utils .CleanPath (m .Destination ) == "/dev" {
174
+ if err := remountReadonly (m ); err != nil {
175
+ return err
174
176
}
175
- break
176
177
}
177
178
}
178
179
@@ -452,12 +453,6 @@ func mountToRootfs(m *configs.Mount, c *mountConfig) error {
452
453
return err
453
454
}
454
455
}
455
- // Initially mounted rw in mountPropagate, remount to ro if flag set.
456
- if m .Flags & unix .MS_RDONLY != 0 {
457
- if err := remount (m , rootfs , mountFd ); err != nil {
458
- return err
459
- }
460
- }
461
456
return nil
462
457
case "bind" :
463
458
if err := prepareBindMount (m , rootfs , mountFd ); err != nil {
@@ -1092,10 +1087,10 @@ func mountPropagate(m *configs.Mount, rootfs string, mountLabel string, mountFd
1092
1087
flags = m .Flags
1093
1088
)
1094
1089
// Delay mounting the filesystem read-only if we need to do further
1095
- // operations on it. We need to set up files in "/dev" and tmpfs mounts may
1096
- // need to be chmod-ed after mounting. The mount will be remounted ro later
1097
- // in finalizeRootfs() if necessary.
1098
- if utils . CleanPath ( m . Destination ) == "/dev " || m . Device == "tmpfs " {
1090
+ // operations on it. We need to set up files in "/dev", and other tmpfs
1091
+ // mounts may need to be chmod-ed after mounting. These mounts will be
1092
+ // remounted ro later in finalizeRootfs(), if necessary.
1093
+ if m . Device == "tmpfs " || utils . CleanPath ( m . Destination ) == "/dev " {
1099
1094
flags &= ^ unix .MS_RDONLY
1100
1095
}
1101
1096
0 commit comments