-/* $OpenBSD: cmd.c,v 1.3 2019/08/01 04:52:56 visa Exp $ */
+/* $OpenBSD: cmd.c,v 1.4 2023/10/20 19:55:49 kn Exp $ */
/*
* Copyright (c) 1997-1999 Michael Shalayeff
return 0;
if (stat(path, &sb) == 0 && S_ISREG(sb.st_mode))
ret = 1;
+ if ((sb.st_mode & S_IXUSR) == 0) {
+ printf("/bsd.upgrade is not u+x\n");
+ ret = 0;
+ }
disk_close();
return ret;
-/* $OpenBSD: rdboot.c,v 1.8 2020/12/09 18:10:19 krw Exp $ */
+/* $OpenBSD: rdboot.c,v 1.9 2023/10/20 19:55:49 kn Exp $ */
/*
* Copyright (c) 2019-2020 Visa Hankala
#define KERNEL "/bsd"
int loadrandom(void);
-void kexec(void);
+void kexec(int);
struct cmd_state cmd;
int octbootfd = -1;
-const char version[] = "1.3";
+const char version[] = "1.4";
int
main(void)
{
char rootdev[PATH_MAX];
- int fd, hasboot;
+ int fd, hasboot, isupgrade = 0;
fd = open(_PATH_CONSOLE, O_RDWR);
login_tty(fd);
if (upgrade()) {
strlcpy(cmd.image, "/bsd.upgrade", sizeof(cmd.image));
printf("upgrade detected: switching to %s\n", cmd.image);
+ isupgrade = 1;
}
hasboot = read_conf();
if (loadrandom() == 0)
cmd.boothowto |= RB_GOODRANDOM;
- kexec();
+ kexec(isupgrade);
hasboot = 0;
strlcpy(cmd.image, KERNEL, sizeof(cmd.image));
}
void
-kexec(void)
+kexec(int isupgrade)
{
struct octboot_kexec_args kargs;
struct stat sb;
goto load_failed;
}
+ /* Prevent re-upgrade: chmod a-x bsd.upgrade */
+ if (isupgrade) {
+ sb.st_mode &= ~(S_IXUSR|S_IXGRP|S_IXOTH);
+ if (fchmod(fd, sb.st_mode) == -1)
+ printf("fchmod a-x %s: failed\n", path);
+ }
+
kimg = malloc(sb.st_size);
if (kimg == NULL)
goto load_failed;