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:
Shiva Prasanth
2019-04-10 10:49:43 -07:00
committed by Shentubot
parent 0e14e48b84
commit 7140b1fdca
3 changed files with 17 additions and 1 deletions
+12
View File
@@ -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)
}
+1 -1
View File
@@ -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"`
+4
View File
@@ -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"));