Page MenuHomePhabricator

[Sanitizers] intercept netent, protoent and mincore on freebsd
ClosedPublic

Authored by devnexen on Sep 5 2021, 12:49 AM.

Diff Detail

Event Timeline

devnexen created this revision.Sep 5 2021, 12:49 AM
devnexen requested review of this revision.Sep 5 2021, 12:49 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 5 2021, 12:49 AM
Herald added a subscriber: Restricted Project. · View Herald Transcript

Can you move tests into Linux. Tests should be trivially ported to Linux. if you don't like to guess Linux changes just put temporarily "REQUIRES: !freebsd", and someone, maybe me, will update tests. Or I can test you changes.

So far I see:

--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
@@ -521,7 +521,7 @@
 #define SANITIZER_INTERCEPT_TTYENT SI_NETBSD
 #define SANITIZER_INTERCEPT_PROTOENT (SI_NETBSD || SI_LINUX || SI_FREEBSD)
 #define SANITIZER_INTERCEPT_PROTOENT_R SI_GLIBC
-#define SANITIZER_INTERCEPT_NETENT (SI_NETBSD || SI_FREEBSD)
+#define SANITIZER_INTERCEPT_NETENT (SI_NETBSD || SI_LINUX || SI_FREEBSD)
 #define SANITIZER_INTERCEPT_SETVBUF \
   (SI_NETBSD || SI_FREEBSD || SI_LINUX || SI_MAC)
 #define SANITIZER_INTERCEPT_GETMNTINFO (SI_NETBSD || SI_FREEBSD || SI_MAC)
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
index 5657f33dc66a..d69b344dd613 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_posix.h
@@ -715,6 +715,13 @@ struct __sanitizer_protoent {
   int p_proto;
 };
 
+struct __sanitizer_netent {
+  char *n_name;
+  char **n_aliases;
+  int n_addrtype;
+  u32 n_net;
+};
+
compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
449–450

please clang format as it asks

compiler-rt/test/sanitizer_common/TestCases/FreeBSD/netent.cpp
3 ↗(On Diff #370784)

up to you, but assert() looks simpler than printf and FileChecks here

compiler-rt/test/sanitizer_common/TestCases/FreeBSD/protoent.cpp
22 ↗(On Diff #370784)

this makes some assumption about buildbot network setup
can you make all them use loopback?

or probably assume getnetbyaddr may return null

vitalybuka added inline comments.Sep 9 2021, 12:34 PM
compiler-rt/test/sanitizer_common/TestCases/FreeBSD/netent.cpp
40 ↗(On Diff #370784)

It can't find like this on my system, but this works

struct netent *lb = getnetbyname("loopback");
struct netent *ntp = getnetbyaddr(lb->n_net, lb->n_addrtype);
76 ↗(On Diff #370784)

I get here:

netent
default 2 0
loopback 2 2130706432
loopback 2 2130706432
default 2 0

devnexen added inline comments.Sep 9 2021, 1:37 PM
compiler-rt/test/sanitizer_common/TestCases/FreeBSD/protoent.cpp
22 ↗(On Diff #370784)

loopback is linux denomination, for freebsd it is your-net but I ll follow your advices using assert and correcting these naming.

devnexen updated this revision to Diff 371720.Sep 9 2021, 1:53 PM
vitalybuka added inline comments.Sep 9 2021, 2:55 PM
compiler-rt/lib/sanitizer_common/sanitizer_platform_limits_freebsd.h
416

It would be nice to clang-format the file in a separate patch.

compiler-rt/test/sanitizer_common/TestCases/FreeBSD/protoent.cpp
3 ↗(On Diff #371720)

I expected you are going to move this one into Linux as well, we already intercept getprotoent

compiler-rt/test/sanitizer_common/TestCases/Linux/netent.cpp
4

getnetent is not intercepted on Linux, so it fails msan
you need either extend sanitizer_platform_limits_posix or remove "linux" from required for now.

devnexen added inline comments.Sep 9 2021, 10:49 PM
compiler-rt/test/sanitizer_common/TestCases/FreeBSD/protoent.cpp
3 ↗(On Diff #371720)

well I hesitated because as you said it s already intercepted and also has an existing test but no problems I can move this.

devnexen added inline comments.Sep 9 2021, 10:52 PM
compiler-rt/test/sanitizer_common/TestCases/Linux/netent.cpp
4

Yes going for make linux intercepting, worth the little effort

devnexen updated this revision to Diff 371790.Sep 9 2021, 11:06 PM

intercepting netent on Linux too

vitalybuka accepted this revision.Sep 10 2021, 11:11 AM

LGTM

compiler-rt/lib/sanitizer_common/sanitizer_platform_interceptors.h
525

order in 523 and 525 are inconsistent

compiler-rt/test/sanitizer_common/TestCases/Linux/netent.cpp
4

Thank you!

This revision is now accepted and ready to land.Sep 10 2021, 11:11 AM