summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormcbride <mcbride@openbsd.org>2015-07-18 05:32:56 +0000
committermcbride <mcbride@openbsd.org>2015-07-18 05:32:56 +0000
commit4a5fd927e46b114e40c1be4bd93ad6354186d149 (patch)
tree05f0aa635e7c488d6f522a6fac814b75aaa31ad9
parentBring up to date with latest changes (diff)
downloadwireguard-openbsd-4a5fd927e46b114e40c1be4bd93ad6354186d149.tar.xz
wireguard-openbsd-4a5fd927e46b114e40c1be4bd93ad6354186d149.zip
Have tftpd provide a block of random data when clients request the file
/etc/random.seed. This allows netbooted systems to inject entropy early in the kernel start. pxeboot requests it already, so no configuration or change is needed on the client side. ok deraadt@ beck@
-rw-r--r--usr.sbin/tftpd/tftpd.813
-rw-r--r--usr.sbin/tftpd/tftpd.c42
2 files changed, 42 insertions, 13 deletions
diff --git a/usr.sbin/tftpd/tftpd.8 b/usr.sbin/tftpd/tftpd.8
index c42d0683c0e..2e8f89cb5cf 100644
--- a/usr.sbin/tftpd/tftpd.8
+++ b/usr.sbin/tftpd/tftpd.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tftpd.8,v 1.4 2012/03/04 07:26:51 jmc Exp $
+.\" $OpenBSD: tftpd.8,v 1.5 2015/07/18 05:32:56 mcbride Exp $
.\"
.\" Copyright (c) 1983, 1991 The Regents of the University of California.
.\" All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" from: @(#)tftpd.8 6.7 (Berkeley) 5/13/91
.\"
-.Dd $Mdocdate: March 4 2012 $
+.Dd $Mdocdate: July 18 2015 $
.Dt TFTPD 8
.Os
.Sh NAME
@@ -70,6 +70,15 @@ The server must be started as root, but will chroot to the
.Ar directory
specified on the command line and drop privileges to the _tftpd user.
.Pp
+.Nm tftpd
+always provides random data at the path
+.Pa /etc/random.seed ,
+and therefore this path will be ignored inside the
+.Ar directory .
+.Ox
+network bootloaders access this path to harvest entropy during
+kernel load.
+.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl 4
diff --git a/usr.sbin/tftpd/tftpd.c b/usr.sbin/tftpd/tftpd.c
index d502d6d1d9a..3f05d419b2c 100644
--- a/usr.sbin/tftpd/tftpd.c
+++ b/usr.sbin/tftpd/tftpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: tftpd.c,v 1.26 2015/01/16 06:40:22 deraadt Exp $ */
+/* $OpenBSD: tftpd.c,v 1.27 2015/07/18 05:32:56 mcbride Exp $ */
/*
* Copyright (c) 2012 David Gwynne <dlg@uq.edu.au>
@@ -91,6 +91,8 @@
#define RETRIES 5
+#define SEEDPATH "/etc/random.seed"
+
struct formats;
enum opt_enum {
@@ -146,6 +148,7 @@ struct tftp_client {
int newline;
int sock;
+ int seed;
};
__dead void usage(void);
@@ -937,6 +940,13 @@ validate_access(struct tftp_client *client, const char *filename)
int fd, wmode;
const char *errstr;
+ if (strcmp(filename, SEEDPATH) == 0) {
+ if (mode != RRQ)
+ return (EACCESS);
+ client->seed = 1;
+ return (0);
+ }
+
/*
* We use a different permissions scheme if `cancreate' is
* set.
@@ -1076,17 +1086,26 @@ file_read(struct tftp_client *client)
dp->th_block = htons(client->block);
buf = (u_int8_t *)dp->th_data;
- for (i = 0; i < client->segment_size; i++) {
- c = client->fgetc(client);
- if (c == EOF) {
- if (ferror(client->file)) {
- nak(client, 100 + EIO);
- return;
+ if (client->seed) {
+ if (client->block * client->segment_size > SEGSIZE) {
+ i = SEGSIZE % client->segment_size;
+ } else {
+ i = client->segment_size;
+ }
+ arc4random_buf(buf, i);
+ } else {
+ for (i = 0; i < client->segment_size; i++) {
+ c = client->fgetc(client);
+ if (c == EOF) {
+ if (ferror(client->file)) {
+ nak(client, 100 + EIO);
+ return;
+ }
+
+ break;
}
-
- break;
+ buf[i] = c;
}
- buf[i] = c;
}
client->buflen = i + 4;
@@ -1300,7 +1319,8 @@ tftp_wrq(int fd, short events, void *arg)
if (n < client->packet_size) {
tftp_wrq_ack_packet(client);
- fclose(client->file);
+ if (client->file != NULL)
+ fclose(client->file);
client->file = NULL;
event_set(&client->sev, client->sock, EV_READ,
tftp_wrq_end, client);