mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
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:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user