eBPF-based security platform
coccinelle: treat commit_file() as an fd ownership sink
John Fastabende7a39ec269db
diff --git a/testing/ci-checks/t0006-check-coccinelle.sh b/testing/ci-checks/t0006-check-coccinelle.shindex e0626b8b..3d7b64ac 100755--- a/testing/ci-checks/t0006-check-coccinelle.sh+++ b/testing/ci-checks/t0006-check-coccinelle.sh@@ -755,6 +755,15 @@ int no_descriptor(int flags, const char *path, char *real){return realpath(path, real) ? flags : -errno;}++int committed(int dirfd, const char *name, const char *tmp, const void *data)+{+ int fd = openat(dirfd, tmp, O_WRONLY | O_CREAT | O_CLOEXEC, 0600);++ if (fd < 0)+ return -errno;+ return commit_file(dirfd, name, tmp, fd, data);+}EOF}diff --git a/testing/coccinelle/fd_leak.cocci b/testing/coccinelle/fd_leak.cocciindex 4c877b92..4d4fdb42 100644--- a/testing/coccinelle/fd_leak.cocci+++ b/testing/coccinelle/fd_leak.cocci@@ -3,7 +3,8 @@//// A descriptor that was opened is closed, returned, stored or handed to// what closes it (fdopen(), fdopendir(), gzdopen(), a BIO with-// BIO_CLOSE) on every path out of the function once the open succeeded.+// BIO_CLOSE, commit_file()) on every path out of the function once the+// open succeeded.// A leak on an error path goes unnoticed in a one-shot command until a// loop or a retry runs out of descriptors, and keeps open what it should// not. The locks of eventlog_lock() and seal_lock() are descriptors too,@@ -45,11 +46,14 @@ if (\(fd < 0\|fd == -1\)) Swhen != fdopendir(fd)when != gzdopen(fd, ...)when != BIO_new_fd(fd, BIO_CLOSE)+ when != commit_file(..., fd, ...)when != \(_exit\|exit\|abort\)(...)(return fd;|return <+... close(fd) ...+>;+|+ return commit_file(..., fd, ...);|return@p2 ...;)@@ -80,11 +84,14 @@ if (\(fd < 0\|fd == -1\)) Swhen != fdopendir(fd)when != gzdopen(fd, ...)when != BIO_new_fd(fd, BIO_CLOSE)+ when != commit_file(..., fd, ...)when != \(_exit\|exit\|abort\)(...)(return fd;|return <+... close(fd) ...+>;+|+ return commit_file(..., fd, ...);|return@p2 ...;)