When a mountpoint is mounted multiple times with different propagation
settings (e.g., first as slave then as shared), getSourceMount would
return the first entry instead of the last one. This caused issues
where Docker would incorrectly report "path is not a shared mount"
even when the most recent mount has shared propagation.
Fix by using >= instead of > when comparing mount path lengths, which
ensures that later entries (with the same path length) are preferred.
This matches the expected behavior where /proc/self/mountinfo lists
mounts in order, and the last entry for a given path represents the
current mount state.
Fixes #43714
Signed-off-by: majiayu000 <1835304752@qq.com>
| ... | ... |
@@ -391,10 +391,11 @@ func getSourceMount(source string) (string, string, error) {
|
| 391 | 391 |
return "", "", fmt.Errorf("Can't find mount point of %s", source)
|
| 392 | 392 |
} |
| 393 | 393 |
|
| 394 |
- // find the longest mount point |
|
| 394 |
+ // find the longest mount point, preferring later entries when there are |
|
| 395 |
+ // multiple mounts at the same path (e.g., with different propagation settings) |
|
| 395 | 396 |
var idx, maxlen int |
| 396 | 397 |
for i := range mi {
|
| 397 |
- if len(mi[i].Mountpoint) > maxlen {
|
|
| 398 |
+ if len(mi[i].Mountpoint) >= maxlen {
|
|
| 398 | 399 |
maxlen = len(mi[i].Mountpoint) |
| 399 | 400 |
idx = i |
| 400 | 401 |
} |