Skip to content

Commit bf0d68f

Browse files
committed
kernelCTF: style guide: further smaller fixes
1 parent 2b1a1ad commit bf0d68f

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

kernelctf/style_guide.md

+35-24
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ mnl_attr_put_u32(nlh, …, htonl(-0x35));
413413

414414
## Naming conventions
415415

416-
Use describing names for including but not limited to: variables, functions, defines.
416+
Use descriptive names for including but not limited to: variables, functions, defines.
417417

418418
Make sure that the name is not misleading.
419419

@@ -597,7 +597,7 @@ void some_func()
597597

598598
## ROP chains
599599

600-
We prefer collecting target related details like symbol, ROP gadget and stack pivot offsets and structure sizes as `#define`s at the top of the file with describing names.
600+
We prefer collecting target related details like symbol, ROP gadget and stack pivot offsets and structure sizes as `#define`s at the top of the file with descriptive names.
601601

602602
The exact kernel symbols names should be used which could be found in the kernel.
603603

@@ -730,7 +730,8 @@ void some_func()
730730
tfd = timerfd_create(CLOCK_MONOTONIC, 0);
731731
732732
} else {
733-
// local variable, conflicts with the other local one
733+
// local variable, conflicts with
734+
// the other local one
734735
int tfd;
735736
736737
// sets a different local variable
@@ -915,7 +916,8 @@ usleep(300*1000);
915916
```c
916917
del_chain(trig_chain_name);
917918
918-
// @sleep(kernel_func="nft_commit_release", desc="wait for victim chain (trig_chain_name) to be freed")
919+
// @sleep(kernel_func="nft_commit_release",
920+
// desc="wait for victim chain (trig_chain_name) to be freed")
919921
usleep(300*1000);
920922
```
921923
</td>
@@ -1053,10 +1055,12 @@ struct nftnl_set * set_elem_triggers[0x200];
10531055

10541056
for(int i = 1 ; i <= 20; i++)
10551057
for (int j = 1 ; j <= 20; j++)
1056-
set_elem_triggers[(i-1) * 20 + (j-1)] = set_elem_trigger;
1058+
set_elem_triggers[(i-1) * 20 + (j-1)] =
1059+
set_elem_trigger;
10571060

10581061
for(int i = 0 ; i < 200; i++)
1059-
nftnl_set_elems_nlmsg_build_payload(nlh, set_elem_triggers[i]);
1062+
nftnl_set_elems_nlmsg_build_payload(nlh,
1063+
set_elem_triggers[i]);
10601064
```
10611065
10621066
The code above:
@@ -1077,10 +1081,12 @@ struct nftnl_set * set_elem_triggers[SPRAY_COUNT];
10771081
10781082
for(int i = 1 ; i <= SPRAY_DIM_X; i++)
10791083
for (int j = 1 ; j <= SPRAY_DIM_Y; j++)
1080-
set_elem_triggers[(i-1) * SPRAY_DIM_Y + (j-1)] = set_elem_trigger;
1084+
set_elem_triggers[(i-1) * SPRAY_DIM_Y + (j-1)] =
1085+
set_elem_trigger;
10811086
10821087
for(int i = 0 ; i < SPRAY_COUNT; i++)
1083-
nftnl_set_elems_nlmsg_build_payload(nlh, set_elem_triggers[i]);
1088+
nftnl_set_elems_nlmsg_build_payload(nlh,
1089+
set_elem_triggers[i]);
10841090
```
10851091
</td>
10861092
</tr>
@@ -1120,7 +1126,7 @@ __u64 lost; // Number of lost events
11201126
</tr>
11211127
</table>
11221128

1123-
## Miscellaneous code quality issues
1129+
## Miscellaneous notes
11241130

11251131
### Code duplication
11261132

@@ -1139,46 +1145,47 @@ You can always add arguments and simple branches to the helper functions if need
11391145
<td valign="top" markdown="1" style="background:rgba(255,0,0,0.05)">
11401146

11411147
```c
1142-
void create_payload_for_trigger()
1148+
void vuln_trigger()
11431149
{
11441150
struct nlmsghdr *nlh = mnl_nlmsg_create_header();
11451151

11461152
… 15 lines of setting of the structure …
11471153

1148-
… 2 lines unique for create_payload_for_trigger
1154+
… 2 lines unique for vuln_trigger
11491155
}
11501156

1151-
void create_payload_for_spray()
1157+
void spray_nlmsg()
11521158
{
11531159
struct nlmsghdr *nlh = mnl_nlmsg_create_header();
11541160

11551161
… same 15 lines of code like previously …
11561162

1157-
… 2 lines unique for create_payload_for_spray
1163+
… 2 lines unique for spray_nlmsg
11581164
}
11591165
```
11601166
</td>
11611167
<td valign="top" markdown="1" style="background:rgba(0,255,0,0.05)">
11621168

11631169
```c
1164-
struct nlmsghdr *prepare_nlmsg(...args...) {
1170+
struct nlmsghdr *util_nlmsg_create(/* args */)
1171+
{
11651172
struct nlmsghdr *nlh = mnl_nlmsg_create_header();
11661173

11671174
… 15 lines of setting of the structure …
11681175
}
11691176

1170-
void create_payload_for_trigger()
1177+
void vuln_trigger()
11711178
{
1172-
struct nlmsghdr *nlh = prepare_nlmsg();
1179+
struct nlmsghdr *nlh = util_nlmsg_create();
11731180

1174-
… 2 lines unique for create_payload_for_trigger
1181+
… 2 lines unique for vuln_trigger
11751182
}
11761183

1177-
void create_payload_for_spray()
1184+
void spray_nlmsg()
11781185
{
1179-
struct nlmsghdr *nlh = prepare_nlmsg();
1186+
struct nlmsghdr *nlh = util_nlmsg_create();
11801187

1181-
… 2 lines unique for create_payload_for_spray
1188+
… 2 lines unique for spray_nlmsg
11821189
}
11831190
```
11841191
</td>
@@ -1198,10 +1205,10 @@ Only use global variables if you really must to. Prefer using local variables in
11981205
<td valign="top" markdown="1" style="background:rgba(255,0,0,0.05)">
11991206
12001207
```c
1201-
// global variable, never used outside of do_epoll_enqueue
1208+
// global variable, never used outside of race_do_epoll_enqueue
12021209
int timefds[0x1000];
12031210
1204-
static void do_epoll_enqueue(int fd, int f)
1211+
static void race_do_epoll_enqueue(int fd, int f)
12051212
{
12061213
12071214
for (int i = 0; i < 0x100; i++)
@@ -1213,12 +1220,12 @@ static void do_epoll_enqueue(int fd, int f)
12131220
</td>
12141221
<td valign="top" markdown="1" style="background:rgba(0,255,0,0.05)">
12151222

1216-
The `timefds` variable was moved inside the `do_epoll_enqueue` function.
1223+
The `timefds` variable was moved inside the `race_do_epoll_enqueue` function.
12171224

12181225
(Also, the array size now matches actual usage - `0x100` instead of `0x1000`.)
12191226

12201227
```c
1221-
static void do_epoll_enqueue(int fd, int f)
1228+
static void race_do_epoll_enqueue(int fd, int f)
12221229
{
12231230
int timefds[0x100];
12241231
@@ -1231,3 +1238,7 @@ static void do_epoll_enqueue(int fd, int f)
12311238
</td>
12321239
</tr>
12331240
</table>
1241+
1242+
### Indentation
1243+
1244+
We prefer 4 spaces.

0 commit comments

Comments
 (0)