github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/sentry/fs/proc/version.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package proc 16 17 import ( 18 "fmt" 19 20 "github.com/SagerNet/gvisor/pkg/context" 21 "github.com/SagerNet/gvisor/pkg/sentry/fs/proc/seqfile" 22 "github.com/SagerNet/gvisor/pkg/sentry/kernel" 23 ) 24 25 // LINT.IfChange 26 27 // versionData backs /proc/version. 28 // 29 // +stateify savable 30 type versionData struct { 31 // k is the owning Kernel. 32 k *kernel.Kernel 33 } 34 35 // NeedsUpdate implements seqfile.SeqSource.NeedsUpdate. 36 func (*versionData) NeedsUpdate(generation int64) bool { 37 return true 38 } 39 40 // ReadSeqFileData implements seqfile.SeqSource.ReadSeqFileData. 41 func (v *versionData) ReadSeqFileData(ctx context.Context, h seqfile.SeqHandle) ([]seqfile.SeqData, int64) { 42 if h != nil { 43 return nil, 0 44 } 45 46 init := v.k.GlobalInit() 47 if init == nil { 48 // Attempted to read before the init Task is created. This can 49 // only occur during startup, which should never need to read 50 // this file. 51 panic("Attempted to read version before initial Task is available") 52 } 53 54 // /proc/version takes the form: 55 // 56 // "SYSNAME version RELEASE (COMPILE_USER@COMPILE_HOST) 57 // (COMPILER_VERSION) VERSION" 58 // 59 // where: 60 // - SYSNAME, RELEASE, and VERSION are the same as returned by 61 // sys_utsname 62 // - COMPILE_USER is the user that build the kernel 63 // - COMPILE_HOST is the hostname of the machine on which the kernel 64 // was built 65 // - COMPILER_VERSION is the version reported by the building compiler 66 // 67 // Since we don't really want to expose build information to 68 // applications, those fields are omitted. 69 // 70 // FIXME(mpratt): Using Version from the init task SyscallTable 71 // disregards the different version a task may have (e.g., in a uts 72 // namespace). 73 ver := init.Leader().SyscallTable().Version 74 return []seqfile.SeqData{ 75 { 76 Buf: []byte(fmt.Sprintf("%s version %s %s\n", ver.Sysname, ver.Release, ver.Version)), 77 Handle: (*versionData)(nil), 78 }, 79 }, 0 80 } 81 82 // LINT.ThenChange(../../fsimpl/proc/task_files.go)