mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Fixed /proc/cpuinfo permissions
This also applies these permissions to other static proc files. Change-Id: I4167e585fed49ad271aa4e1f1260babb3239a73d PiperOrigin-RevId: 242898575
This commit is contained in:
committed by
Shentubot
parent
0e14e48b84
commit
7140b1fdca
@@ -452,3 +452,15 @@ type InodeGenericChecker struct{}
|
||||
func (InodeGenericChecker) Check(ctx context.Context, inode *fs.Inode, p fs.PermMask) bool {
|
||||
return fs.ContextCanAccessFile(ctx, inode, p)
|
||||
}
|
||||
|
||||
// InodeDenyWriteChecker implements fs.InodeOperations.Check which denies all
|
||||
// write operations.
|
||||
type InodeDenyWriteChecker struct{}
|
||||
|
||||
// Check implements fs.InodeOperations.Check.
|
||||
func (InodeDenyWriteChecker) Check(ctx context.Context, inode *fs.Inode, p fs.PermMask) bool {
|
||||
if p.Write {
|
||||
return false
|
||||
}
|
||||
return fs.ContextCanAccessFile(ctx, inode, p)
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ func (i *taskOwnedInodeOps) UnstableAttr(ctx context.Context, inode *fs.Inode) (
|
||||
//
|
||||
// +stateify savable
|
||||
type staticFileInodeOps struct {
|
||||
fsutil.InodeGenericChecker `state:"nosave"`
|
||||
fsutil.InodeDenyWriteChecker `state:"nosave"`
|
||||
fsutil.InodeNoExtendedAttributes `state:"nosave"`
|
||||
fsutil.InodeNoopRelease `state:"nosave"`
|
||||
fsutil.InodeNoopTruncate `state:"nosave"`
|
||||
|
||||
@@ -725,6 +725,10 @@ TEST(ProcCpuinfo, RequiredFieldsArePresent) {
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ProcCpuinfo, DeniesWrite) {
|
||||
EXPECT_THAT(open("/proc/cpuinfo", O_WRONLY), SyscallFailsWithErrno(EACCES));
|
||||
}
|
||||
|
||||
// Sanity checks that uptime is present.
|
||||
TEST(ProcUptime, IsPresent) {
|
||||
std::string proc_uptime = ASSERT_NO_ERRNO_AND_VALUE(GetContents("/proc/uptime"));
|
||||
|
||||
Reference in New Issue
Block a user