cgroup/cpuset: handle the offset argument of write methods properly

offset is an offset in a file, so here is no sense to
drop first "offset" number of bytes from a buffer.

Reported-by: syzbot+b9610cff22c10d9bead4@syzkaller.appspotmail.com
PiperOrigin-RevId: 413553935
This commit is contained in:
Andrei Vagin
2021-12-01 17:58:07 -08:00
committed by gVisor bot
parent 054229a46b
commit b2f8b495ad
3 changed files with 2 additions and 5 deletions
+1 -2
View File
@@ -234,11 +234,10 @@ func (d *tasksData) Write(ctx context.Context, src usermem.IOSequence, offset in
// parseInt64FromString interprets src as string encoding a int64 value, and
// returns the parsed value.
func parseInt64FromString(ctx context.Context, src usermem.IOSequence, offset int64) (val, len int64, err error) {
func parseInt64FromString(ctx context.Context, src usermem.IOSequence) (val, len int64, err error) {
const maxInt64StrLen = 20 // i.e. len(fmt.Sprintf("%d", math.MinInt64)) == 20
t := kernel.TaskFromContext(ctx)
src = src.DropFirst64(offset)
buf := t.CopyScratchBuffer(maxInt64StrLen)
n, err := src.CopyIn(ctx, buf)
-2
View File
@@ -82,7 +82,6 @@ func (d *cpusData) Generate(ctx context.Context, buf *bytes.Buffer) error {
// Write implements vfs.WritableDynamicBytesSource.Write.
func (d *cpusData) Write(ctx context.Context, src usermem.IOSequence, offset int64) (int64, error) {
src = src.DropFirst64(offset)
if src.NumBytes() > hostarch.PageSize {
return 0, linuxerr.EINVAL
}
@@ -127,7 +126,6 @@ func (d *memsData) Generate(ctx context.Context, buf *bytes.Buffer) error {
// Write implements vfs.WritableDynamicBytesSource.Write.
func (d *memsData) Write(ctx context.Context, src usermem.IOSequence, offset int64) (int64, error) {
src = src.DropFirst64(offset)
if src.NumBytes() > hostarch.PageSize {
return 0, linuxerr.EINVAL
}
+1 -1
View File
@@ -55,7 +55,7 @@ func (d *jobIDData) Generate(ctx context.Context, buf *bytes.Buffer) error {
// Write implements vfs.WritableDynamicBytesSource.Write.
func (d *jobIDData) Write(ctx context.Context, src usermem.IOSequence, offset int64) (int64, error) {
val, n, err := parseInt64FromString(ctx, src, offset)
val, n, err := parseInt64FromString(ctx, src)
if err != nil {
return n, err
}