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

Fix buffer overread and overrun in ipc #89

Merged
merged 1 commit into from
Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const int BYTES_PER_PIXEL = sizeof(uint16_t);
uint16_t *shared_mem;

void doUpdate(SwtFB &fb, const swtfb_update &s) {
auto mxcfb_update = s.update;
auto mxcfb_update = s.mdata.update;
auto rect = mxcfb_update.update_region;

#ifdef DEBUG_DIRTY
Expand Down Expand Up @@ -147,15 +147,15 @@ int server_main(int, char **, char **) {
doUpdate(fb, buf);
break;
case ipc::XO_t: {
int width = buf.xochitl_update.x2 - buf.xochitl_update.x1 + 1;
int height = buf.xochitl_update.y2 - buf.xochitl_update.y1 + 1;
QRect rect(buf.xochitl_update.x1, buf.xochitl_update.y1, width, height);
fb.SendUpdate(rect, buf.xochitl_update.waveform,
buf.xochitl_update.flags);
const xochitl_data& data = buf.mdata.xochitl_update;
int width = data.x2 - data.x1 + 1;
int height = data.y2 - data.y1 + 1;
QRect rect(data.x1, data.y1, width, height);
fb.SendUpdate(rect, data.waveform, data.flags);
} break;
case ipc::WAIT_t: {
fb.WaitForLastUpdate();
sem_t* sem = sem_open(buf.wait_update.sem_name, O_CREAT, 0644, 0);
sem_t* sem = sem_open(buf.mdata.wait_update.sem_name, O_CREAT, 0644, 0);
if (sem != NULL) {
sem_post(sem);
sem_close(sem);
Expand Down
29 changes: 15 additions & 14 deletions src/shared/ipc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,19 @@ struct wait_sem_data {

struct swtfb_update {
long mtype;
struct {
union {
xochitl_data xochitl_update;

union {
xochitl_data xochitl_update;
struct mxcfb_update_data update;
wait_sem_data wait_update;

struct mxcfb_update_data update;
wait_sem_data wait_update;

};
};

#ifdef DEBUG_TIMING
uint64_t ms;
uint64_t ms;
#endif
} mdata;
};

const int WIDTH = 1404;
Expand Down Expand Up @@ -133,9 +134,9 @@ class Queue {
void send(wait_sem_data data) {
swtfb_update msg;
msg.mtype = WAIT_t;
msg.wait_update = data;
msg.mdata.wait_update = data;

int wrote = msgsnd(msqid, (void *)&msg, sizeof(swtfb_update), 0);
int wrote = msgsnd(msqid, (void *)&msg, sizeof(msg.mdata.wait_update), 0);
if (wrote != 0) {
perror("Error sending wait update");
}
Expand All @@ -144,9 +145,9 @@ class Queue {
void send(xochitl_data data) {
swtfb_update msg;
msg.mtype = XO_t;
msg.xochitl_update = data;
msg.mdata.xochitl_update = data;

int wrote = msgsnd(msqid, (void *)&msg, sizeof(swtfb_update), 0);
int wrote = msgsnd(msqid, (void *)&msg, sizeof(msg.mdata.xochitl_update), 0);
if (wrote != 0) {
perror("Error sending xochitl update");
}
Expand All @@ -162,12 +163,12 @@ class Queue {

swtfb_update swtfb_msg;
swtfb_msg.mtype = UPDATE_t;
swtfb_msg.update = msg;
swtfb_msg.mdata.update = msg;

#ifdef DEBUG_TIMING
swtfb_msg.ms = get_now();
#endif
int wrote = msgsnd(msqid, (void *)&swtfb_msg, sizeof(swtfb_msg), 0);
int wrote = msgsnd(msqid, (void *)&swtfb_msg, sizeof(swtfb_msg.mdata.update), 0);
if (wrote != 0) {
cerr << "ERRNO " << errno << endl;
}
Expand All @@ -176,7 +177,7 @@ class Queue {
swtfb_update recv() {
swtfb_update buf;
errno = 0;
auto len = msgrcv(msqid, &buf, sizeof(buf), 0, 0);
auto len = msgrcv(msqid, &buf, sizeof(buf.mdata), 0, MSG_NOERROR);
#ifdef DEBUG_TIMING
auto rect = buf.update.update_region;
cerr << get_now() - buf.ms << "ms MSG Q RECV " << rect.left << " "
Expand Down