From 6521acf8f163052c94da9638575aa17b299390b1 Mon Sep 17 00:00:00 2001 From: Kr328 Date: Wed, 22 Jul 2020 20:22:34 +0800 Subject: [PATCH] Improve: check uid on process search & fix typo (#824) --- rules/process_linux.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rules/process_linux.go b/rules/process_linux.go index 6c71b73c..cc41da90 100644 --- a/rules/process_linux.go +++ b/rules/process_linux.go @@ -36,7 +36,7 @@ type ProcessNameResolver func(inode, uid int) (name string, err error) // export for android var ( DefaultSocketResolver SocketResolver = resolveSocketByNetlink - DefaultProcessNameResolver ProcessNameResolver = resolveProcessNameByProcSeach + DefaultProcessNameResolver ProcessNameResolver = resolveProcessNameByProcSearch ) type Process struct { @@ -225,7 +225,7 @@ func unpackSocketDiagResponse(msg *syscall.NetlinkMessage) (inode, uid uint32) { return } -func resolveProcessNameByProcSeach(inode, _ int) (string, error) { +func resolveProcessNameByProcSearch(inode, uid int) (string, error) { files, err := ioutil.ReadDir(pathProc) if err != nil { return "", err @@ -235,7 +235,11 @@ func resolveProcessNameByProcSeach(inode, _ int) (string, error) { socket := []byte(fmt.Sprintf("socket:[%d]", inode)) for _, f := range files { - if !isPid(f.Name()) { + if !f.IsDir() || !isPid(f.Name()) { + continue + } + + if f.Sys().(*syscall.Stat_t).Uid != uint32(uid) { continue }