sync with OpenBSD -current

This commit is contained in:
purplerain 2024-01-23 02:37:53 +00:00
parent 59bb6de060
commit 40c5de4fdf
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
2 changed files with 64 additions and 61 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: privsep.c,v 1.3 2023/12/14 09:44:15 claudio Exp $ */ /* $OpenBSD: privsep.c,v 1.4 2024/01/22 10:13:34 claudio Exp $ */
/* /*
* Copyright 2001 Niels Provos <provos@citi.umich.edu> * Copyright 2001 Niels Provos <provos@citi.umich.edu>
* All rights reserved. * All rights reserved.
@ -118,7 +118,6 @@ send_cmd(struct imsgbuf *ibuf, char *user, char *pass, char *style)
warn("imsg_add"); warn("imsg_add");
return -1; return -1;
} }
wbuf->fd = -1;
imsg_close(ibuf, wbuf); imsg_close(ibuf, wbuf);
if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN) { if ((n = msgbuf_write(&ibuf->w)) == -1 && errno != EAGAIN) {
@ -130,63 +129,64 @@ send_cmd(struct imsgbuf *ibuf, char *user, char *pass, char *style)
return 0; return 0;
} }
static char *
ibuf_get_string(struct ibuf *buf, size_t len)
{
char *str;
if (ibuf_size(buf) < len) {
errno = EBADMSG;
return (NULL);
}
str = strndup(ibuf_data(buf), len);
if (str == NULL)
return (NULL);
buf->rpos += len;
return (str);
}
static int static int
receive_cmd(struct imsgbuf *ibuf, char **name, char **pass, char **style) receive_cmd(struct imsgbuf *ibuf, char **name, char **pass, char **style)
{ {
struct imsg imsg; struct imsg imsg;
struct ibuf buf;
struct priv_cmd_hdr hdr; struct priv_cmd_hdr hdr;
ssize_t n, nread, datalen; ssize_t n, nread;
void *data;
if ((nread = imsg_read(ibuf)) == -1 && errno != EAGAIN) { do {
warn("imsg_read"); if ((nread = imsg_read(ibuf)) == -1 && errno != EAGAIN) {
return -1; warn("imsg_read");
} return -1;
if (nread == 0) { }
/* parent exited */ if (nread == 0) {
exit(0); /* parent exited */
} exit(0);
if ((n = imsg_get(ibuf, &imsg)) == -1) { }
warnx("imsg_get"); if ((n = imsg_get(ibuf, &imsg)) == -1) {
return -1; warnx("imsg_get");
} return -1;
if (imsg.hdr.type != XLOCK_CHECKPW_CMD) { }
} while (n == 0);
if (imsg_get_type(&imsg) != XLOCK_CHECKPW_CMD) {
warnx("invalid command"); warnx("invalid command");
imsg_free(&imsg); goto fail;
return -1;
} }
datalen = imsg.hdr.len - IMSG_HEADER_SIZE; if (imsg_get_ibuf(&imsg, &buf) == -1 ||
data = imsg.data; ibuf_get(&buf, &hdr, sizeof(hdr)) == -1 ||
if (datalen < sizeof(struct priv_cmd_hdr)) { (*name = ibuf_get_string(&buf, hdr.namelen)) == NULL ||
warnx("truncated header"); (*pass = ibuf_get_string(&buf, hdr.passlen)) == NULL) {
imsg_free(&imsg); warn("truncated message");
return -1; goto fail;
} }
memcpy(&hdr, data, sizeof(struct priv_cmd_hdr));
if (datalen != sizeof(hdr) + hdr.namelen + hdr.passlen + hdr.stylelen) {
warnx("truncated strings");
imsg_free(&imsg);
return -1;
}
data += sizeof(struct priv_cmd_hdr);
*name = strndup(data, hdr.namelen);
if (*name == NULL)
goto nomem;
data += hdr.namelen;
*pass = strndup(data, hdr.passlen);
if (*pass == NULL)
goto nomem;
data += hdr.passlen;
if (hdr.stylelen != 0) { if (hdr.stylelen != 0) {
*style = strndup(data, hdr.stylelen); if ((*style = ibuf_get_string(&buf, hdr.stylelen)) == NULL) {
if (*style == NULL) warn("truncated message");
goto nomem; goto fail;
} else }
*style = NULL; }
imsg_free(&imsg); imsg_free(&imsg);
return 0; return 0;
nomem: fail:
warn("strndup");
imsg_free(&imsg); imsg_free(&imsg);
return -1; return -1;
} }
@ -202,21 +202,21 @@ send_result(struct imsgbuf *ibuf, int result)
static int static int
receive_result(struct imsgbuf *ibuf, int *presult) receive_result(struct imsgbuf *ibuf, int *presult)
{ {
ssize_t nread, n; ssize_t n, nread;
int retval = 0; int retval = 0;
struct imsg imsg; struct imsg imsg;
if ((nread = imsg_read(ibuf)) == -1 && errno != EAGAIN) do {
return -1; if ((nread = imsg_read(ibuf)) == -1 && errno != EAGAIN)
if (nread == 0) return -1;
return -1; if (nread == 0)
if ((n = imsg_get(ibuf, &imsg)) == -1) return -1;
return -1; if ((n = imsg_get(ibuf, &imsg)) == -1)
if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(int)) return -1;
} while (n == 0);
if (imsg_get_type(&imsg) != XLOCK_CHECKPW_RESULT ||
imsg_get_data(&imsg, presult, sizeof(*presult)) == -1)
retval = -1; retval = -1;
if (imsg.hdr.type != XLOCK_CHECKPW_RESULT)
retval = -1;
memcpy(presult, imsg.data, sizeof(int));
imsg_free(&imsg); imsg_free(&imsg);
return retval; return retval;
} }
@ -267,13 +267,16 @@ priv_init(gid_t gid)
err(1, "pledge"); err(1, "pledge");
while (1) { while (1) {
user = pass = style = NULL;
if (receive_cmd(&child_ibuf, &user, &pass, &style) == -1) { if (receive_cmd(&child_ibuf, &user, &pass, &style) == -1) {
warn("receive_cmd"); warn("receive_cmd");
result = 0; result = 0;
} else } else
result = pw_check(user, pass, style); result = pw_check(user, pass, style);
freezero(user, strlen(user)); if (user != NULL)
freezero(pass, strlen(pass)); freezero(user, strlen(user) + 1);
if (pass != NULL)
freezero(pass, strlen(pass) + 1);
free(style); free(style);
if (send_result(&child_ibuf, result) == -1) if (send_result(&child_ibuf, result) == -1)
warn("send_result"); warn("send_result");

View file

@ -246,7 +246,7 @@ listPossibleVideoDrivers(XF86MatchedDrivers *md)
xf86PciMatchDriver(md); xf86PciMatchDriver(md);
break; break;
#endif #endif
case WSDISPLAY_TYPE_RKDRM: case WSDISPLAY_TYPE_KMS:
xf86AddMatchedDriver(md, "modesetting"); xf86AddMatchedDriver(md, "modesetting");
break; break;
case WSDISPLAY_TYPE_IFB: case WSDISPLAY_TYPE_IFB: