Skip to content

Commit 56443da

Browse files
committed
feat(relro): detect BIND_NOW via DT_FLAGS_1 (DF_1_NOW) and use bitmask for DF_BIND_NOW
Add support for detecting RELRO/BIND_NOW through DT_FLAGS_1 (DF_1_NOW), in addition to DT_BIND_NOW and DT_FLAGS. Also switch DF_BIND_NOW check from equality (8) to a proper bitmask, and rename variables to Go-style camelCase for clarity.
1 parent d24d88d commit 56443da

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

pkg/checksec/relro.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,25 @@ func RELRO(name string) *relro {
3434
// check both bind and bind_flag.
3535
// if DT_BIND_NOW == 0, then it is set
3636
// if DT_FLAGS == 8, then DF_BIND_NOW is set
37+
// if DT_FLAGS_1 == 1, then DF_1_NOW is set
3738
// this is depending on the compiler version used.
3839
bind, _ := file.DynValue(elf.DT_BIND_NOW)
3940
if len(bind) == 0 {
4041
bind, _ = DynValueFromPTDynamic(file, elf.DT_BIND_NOW)
4142
}
42-
bind_flag, _ := file.DynValue(elf.DT_FLAGS)
43-
if len(bind_flag) == 0 {
44-
bind_flag, _ = DynValueFromPTDynamic(file, elf.DT_FLAGS)
43+
bindFlag, _ := file.DynValue(elf.DT_FLAGS)
44+
if len(bindFlag) == 0 {
45+
bindFlag, _ = DynValueFromPTDynamic(file, elf.DT_FLAGS)
4546
}
4647

47-
if (len(bind) > 0 && bind[0] == 0) || (len(bind_flag) > 0 && bind_flag[0] == 8) {
48+
bindFlag1, _ := file.DynValue(elf.DT_FLAGS_1)
49+
if len(bindFlag1) == 0 {
50+
bindFlag1, _ = DynValueFromPTDynamic(file, elf.DT_FLAGS_1)
51+
}
52+
53+
if (len(bind) > 0 && bind[0] == 0) ||
54+
(len(bindFlag) > 0 && (bindFlag[0]&uint64(elf.DF_BIND_NOW)) != 0) ||
55+
(len(bindFlag1) > 0 && (bindFlag1[0]&uint64(elf.DF_1_NOW)) != 0) {
4856
bindNow = true
4957
}
5058

0 commit comments

Comments
 (0)