Skip to content

Commit 0f83910

Browse files
committed
[kernel] Various minor kernel bug fixes found by AI
1 parent b491d54 commit 0f83910

11 files changed

Lines changed: 28 additions & 17 deletions

File tree

elks/Makefile-rules

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ include $(TOPDIR)/Make.defs
5757

5858
VERSION = 0 # (0-255)
5959
PATCHLEVEL = 9 # (0-255)
60-
SUBLEVEL = 0 # (0-255)
61-
PRE =
60+
SUBLEVEL = 1 # (0-255)
61+
PRE = pre
6262

6363
#########################################################################
6464
# Specify the architecture we will use.

elks/arch/i86/drivers/char/pty.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,13 @@ int pty_select (struct inode *inode, struct file *file, int sel_type)
7777
/* /dev/ptyp0 master read (from slave /dev/ttyp0 outq to telnetd) */
7878
size_t pty_read (struct inode *inode, struct file *file, char *data, size_t len)
7979
{
80+
struct tty *tty = determine_tty (inode->i_rdev); /* get slave TTY*/
8081
size_t count = 0;
8182
int err;
8283

83-
struct tty *tty = determine_tty (inode->i_rdev); /* get slave TTY*/
84-
if (tty == NULL) return -EBADF;
85-
86-
/* return EOF on master closed*/
87-
if (!tty->usecount)
84+
if (tty == NULL)
85+
return -EBADF;
86+
if (!tty->usecount) /* return EOF on master closed*/
8887
return 0;
8988

9089
while (count < len) {
@@ -106,11 +105,14 @@ size_t pty_read (struct inode *inode, struct file *file, char *data, size_t len)
106105
/* /dev/ptyp0 master write (from telnetd to slave /dev/ttyp0 inq) */
107106
size_t pty_write (struct inode *inode, struct file *file, char *data, size_t len)
108107
{
108+
struct tty *tty = determine_tty (inode->i_rdev); /* get slave TTY*/
109109
size_t count = 0;
110110
int ret;
111111

112-
struct tty *tty = determine_tty (inode->i_rdev); /* get slave TTY*/
113-
if (tty == NULL) return -EBADF;
112+
if (tty == NULL)
113+
return -EBADF;
114+
if (!tty->usecount)
115+
return -EIO;
114116

115117
while (count < len) {
116118
ret = chq_wait_wr (&tty->inq, (file->f_flags & O_NONBLOCK) | count);

elks/arch/i86/kernel/process.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,16 @@ void arch_setup_user_stack (register struct task_struct * t, word_t entry, seg_t
104104
* as we don't have any way of sorting out a return value yet.
105105
*/
106106

107-
void arch_setup_sighandler_stack(register struct task_struct *t,
107+
int arch_setup_sighandler_stack(register struct task_struct *t,
108108
__kern_sighandler_t addr,unsigned signr)
109109
{
110+
segoff_t sp = t->t_regs.sp;
111+
110112
debug("Stack %x:%x was %x %x %x %x\n", _FP_SEG(addr), _FP_OFF(addr),
111113
get_ustack(t,0), get_ustack(t,2), get_ustack(t,4), get_ustack(t,6));
114+
115+
if (sp > t->t_begstack || sp < t->t_endbrk + 6)
116+
return -1;
112117
put_ustack(t, -6, (int)get_ustack(t,0));
113118
put_ustack(t, -4, _FP_OFF(addr));
114119
put_ustack(t, -2, _FP_SEG(addr));
@@ -118,6 +123,7 @@ void arch_setup_sighandler_stack(register struct task_struct *t,
118123
debug("Stack is %x %x %x %x %x %x %x\n", get_ustack(t,0), get_ustack(t,2),
119124
get_ustack(t,4), get_ustack(t,6), get_ustack(t,8), get_ustack(t,10),
120125
get_ustack(t,12));
126+
return 0;
121127
}
122128

123129
/*

elks/arch/i86/kernel/signal.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ void do_signal(void)
7171
else if (*sd != SIGDISP_IGN) { /* Set handler */
7272
debug_sig("SIGNAL(%P) calling handler %x:%x\n",
7373
_FP_SEG(sah), _FP_OFF(sah));
74-
arch_setup_sighandler_stack(current, sah, signr);
74+
if (arch_setup_sighandler_stack(current, sah, signr) < 0)
75+
do_exit(SIGSEGV);
7576
*sd = SIGDISP_DFL;
7677
clr_irq(); /* stop race between reset signal and return to user */
7778
current->signal &= ~mask;

elks/arch/i86/kernel/timer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void timer_bh(void)
9696
#endif
9797

9898
#if defined(CONFIG_BLK_DEV_SSD_TEST) && defined(CONFIG_ASYNCIO)
99-
if (ssd_timeout && time_after(jiffies, ssd_timeout))
99+
if (ssd_timeout && time_after(jiffies(), ssd_timeout))
100100
ssd_io_complete();
101101
#endif
102102

elks/arch/i86/mm/xms.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ void xms_fmemcpyb(void *dst_off, ramdesc_t dst_seg, void *src_off, ramdesc_t src
155155
else {
156156
/* lots of extra work on odd transfers because INT 15 block moves words only */
157157
if ((count & 1) && xms_enabled == XMS_INT15) {
158-
static char buf[2];
158+
char buf[2];
159159
size_t wc = count >> 1;
160160

161161
if (wc)

elks/fs/msdos/dir.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ int FATPROC msdos_get_entry_long(
145145
int i,i2,last;
146146
int long_len = 0;
147147
unsigned char c;
148-
ASYNCIO_REENTRANT char longname[14];
148+
ASYNCIO_REENTRANT char longname[15];
149149

150150
if (is_long) {
151151
unsigned char sum;

elks/fs/pipe.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,13 @@ static int pipe_rdwr_open(register struct inode *inode,
229229
}
230230

231231
if (filp->f_mode & FMODE_WRITE) {
232+
if (!PIPE_READERS(inode) && filp->f_flags & O_NONBLOCK)
233+
return -ENXIO;
232234
PIPE_WRITERS(inode)++;
233235
if (PIPE_READERS(inode) > 0) {
234236
if (PIPE_WRITERS(inode) < 2)
235237
wake_up_interruptible(&PIPE_WAIT(inode));
236238
} else {
237-
if (filp->f_flags & O_NONBLOCK) return -ENXIO;
238239
while (!PIPE_READERS(inode))
239240
interruptible_sleep_on(&PIPE_WAIT(inode));
240241
}

elks/fs/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ static struct super_block *read_super(kdev_t dev, int t, int flags,
184184
break;
185185
}
186186

187+
memset(s, 0, sizeof(*s));
187188
s->s_dev = dev;
188189
s->s_flags = flags;
189190

elks/include/linuxmt/signal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ struct __kern_sigaction_struct {
240240
#ifdef __KERNEL__
241241
struct task_struct;
242242
int send_sig(sig_t,struct task_struct *,int);
243-
void arch_setup_sighandler_stack(struct task_struct *, __kern_sighandler_t,unsigned);
243+
int arch_setup_sighandler_stack(struct task_struct *, __kern_sighandler_t, unsigned);
244244
int sys_kill(pid_t, sig_t);
245245
void do_signal(void);
246246
#endif /* __KERNEL__*/

0 commit comments

Comments
 (0)