Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cc1120 random number generator and stack smashing protection #297

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

Cathouwu
Copy link
Contributor

@Cathouwu Cathouwu commented Jun 30, 2024

Purpose

Created a number generator function from the c1120 to generate a stack canary for stack overflow protection:

https://www.notion.so/uworbital/6375c5c5dcf1485e8a6c47f18d419ae5?v=72baf90d01f643b09d77418bd3f53b14&p=02e40c1185bb439d93fd92288137edcc&pm=s

New Changes

  • Added a random number generator function in the cc1120 file.
  • Modified state_mgr to initialize peripherals and cc1120. Changed stack guard after cc1120 is initialized.

Testing

  • Tested that the cc1120 can generate random numbers
  • Tested that the stack canary in app_main is updated with the random number.

Stack canaries generated (generated after every reboot: )
image

Outstanding Changes

  • n/a

Copy link

Pull reviewers stats

Stats of the last 120 days for UWOrbital:

User Total reviews Time to review Total comments
Yarik-Popov 16 5d 4h 21m 112
dgobalak 5 1h 30m 16
Gjjjiang 4 18h 47m 22
PratyushMakkar 4 6d 5h 12m 27
Navtajh04 2 27d 14h 6
kepler452b123 1 9h 15m 4
⚡️ Pull request stats

@@ -40,6 +59,8 @@ int main(void) {
initSciMutex();
initI2CMutex();
initSpiMutex();
cc1120Init();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Navtajh04 any issues with this being called twice? I think we also call this in comms mgr.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I would remove this from here and change the stack guard from comms mgr. We aren't really susceptible to any kind of stack smashing attacks until comms is established anyways

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

especially since this is accessing cc1120, we should do it in comms mgr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

obc/app/app_main.c Outdated Show resolved Hide resolved
obc/app/drivers/cc1120/cc1120_mcu.h Outdated Show resolved Hide resolved
obc/app/drivers/cc1120/cc1120.c Outdated Show resolved Hide resolved
obc/app/app_main.c Outdated Show resolved Hide resolved
obc/app/app_main.c Outdated Show resolved Hide resolved
obc/app/drivers/cc1120/cc1120.c Outdated Show resolved Hide resolved
obc/app/drivers/cc1120/cc1120.c Outdated Show resolved Hide resolved
obc/app/drivers/cc1120/cc1120.h Outdated Show resolved Hide resolved
obc/app/app_main.c Outdated Show resolved Hide resolved
obc/app/sys/obc_errors.h Outdated Show resolved Hide resolved
@Yarik-Popov Yarik-Popov dismissed their stale review July 27, 2024 20:24

Already handled

@@ -40,6 +59,8 @@ int main(void) {
initSciMutex();
initI2CMutex();
initSpiMutex();
cc1120Init();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I would remove this from here and change the stack guard from comms mgr. We aren't really susceptible to any kind of stack smashing attacks until comms is established anyways

Comment on lines 30 to 32
uint32_t __stack_chk_guard_init(void);

uint32_t __stack_chk_guard_change(void) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

double __ is usually reserved for compiler specific stuff (ex: __stack_chk_guard is a special variable name used by GCC) so for these 2 helper functions we are defining ourselves (not special compiler keywords) we should use our regular function naming convention

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

@@ -40,6 +59,8 @@ int main(void) {
initSciMutex();
initI2CMutex();
initSpiMutex();
cc1120Init();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

especially since this is accessing cc1120, we should do it in comms mgr

#define CC1120_SPI_PORT spiPORT4
#define CC1120_SPI_CS 0
#define CC1120_SPI_PORT spiPORT3
#define CC1120_SPI_CS 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be changed, cc1120 is on SPI port 4 on obc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverted

obc/app/app_main.c Outdated Show resolved Hide resolved
obc/app/app_main.c Outdated Show resolved Hide resolved
@Yarik-Popov Yarik-Popov changed the title Tested cc1120 random number generator and stack smashing protection Add cc1120 random number generator and stack smashing protection Sep 7, 2024
Copy link
Contributor

@kepler452b123 kepler452b123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some nits, otherwise lgtm

Comment on lines +1 to +3
#include "obc_print.h"
#include "obc_sci_io.h"
#include <sci.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

Comment on lines +3 to +6
#include "obc_sci_io.h"
#include "cc1120_txrx.h"
#include "cc1120.h"
#include "obc_print.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove sci_io and print. move cc1120 includes to lines after #include lm75bd.h


#include <FreeRTOS.h>
#include <os_portmacro.h>
#include <os_queue.h>
#include <os_task.h>
#include <sys_common.h>
#include <sci.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove


#if defined(DEBUG) && !defined(OBC_REVISION_2)
#include <gio.h>
#endif

extern void *__stack_chk_guard;
#define STACK_BYTES 4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not a completely accurate name, i would make it more specific. e.g. STACK_CANARY_BYTES

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants