mirror of
https://github.com/docker/cli.git
synced 2026-08-28 18:14:28 -05:00
- user: prevent possible DoS via unbounded parsing of user and group database files in GHSA-mjcv-p78q-w5fw. This fixes a similar issue as CVE-2026-47262 in containerd. - user: prevent falling back to looking up numeric usernames Improve handling of numeric user/group to prevent looking up numeric values as usernames. This fixes a similar issue as [CVE-2026-46680] in containerd. - user: update minimum go version to go1.18 - assorted testing and linting fixes. [CVE-2026-46680]: https://github.com/advisories/GHSA-fqw6-gf59-qr4w full diff: https://github.com/moby/sys/compare/user/v0.4.0...user/v0.4.1 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package user
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
// maxUserFileBytes caps how much data is read from any user-database file.
|
|
// User database files are expected to be relatively small. 10 MiB provides
|
|
// generous headroom while bounding memory usage.
|
|
const maxUserFileBytes = 10 << 20
|
|
|
|
// openUserFile attempts to open a user-database file with a limitedFile
|
|
// capped at maxUserFileBytes. It produces an error if the given path is
|
|
// a non-regular file.
|
|
func openUserFile(path string) (*limitedFile, error) {
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
info, err := f.Stat()
|
|
if err != nil {
|
|
_ = f.Close()
|
|
return nil, err
|
|
}
|
|
if !info.Mode().IsRegular() {
|
|
_ = f.Close()
|
|
return nil, &os.PathError{
|
|
Op: "open",
|
|
Path: path,
|
|
Err: errors.New("not a regular file"),
|
|
}
|
|
}
|
|
|
|
return &limitedFile{
|
|
File: f,
|
|
// Allow one byte past the cap so an overflow surfaces as an
|
|
// error rather than a silent EOF that the parser would treat as
|
|
// a clean end-of-file (and miss any entries past the cap).
|
|
LimitedReader: &io.LimitedReader{R: f, N: maxUserFileBytes + 1},
|
|
name: path,
|
|
}, nil
|
|
}
|
|
|
|
type limitedFile struct {
|
|
*os.File
|
|
*io.LimitedReader
|
|
name string
|
|
}
|
|
|
|
func (l *limitedFile) Read(p []byte) (int, error) {
|
|
n, err := l.LimitedReader.Read(p)
|
|
if l.LimitedReader.N == 0 {
|
|
return n, &os.PathError{
|
|
Op: "read",
|
|
Path: l.name,
|
|
Err: fmt.Errorf("file exceeds %d bytes", maxUserFileBytes),
|
|
}
|
|
}
|
|
return n, err
|
|
}
|