Skip to content

Commit 5bfb304

Browse files
committed
Allow secure-netboot
When doing file verification, tftp needs to be able to handle multiple open files concurrently. We also need tftp_stat() to provide useful values for st_dev and st_ino. Allow an architecture to define NETPROTO_DEFAULT. The default is NET_NFS for backwards compatability. In net_parse_rootpath() fix parsing of <scheme>://<ip>[:<port]/<path> and ensure we return INADDR_NONE unless we successfully parsed an addr, so we don't end up clobbering rootip obtained from bootp(). Sponsored by: Juniper Networks, Inc. Differential Revision: https://reviews.freebsd.org/D51187
1 parent b44cc1b commit 5bfb304

File tree

7 files changed

+140
-55
lines changed

7 files changed

+140
-55
lines changed

stand/common/dev_net.c

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@
6666
#include "dev_net.h"
6767
#include "bootstrap.h"
6868

69+
#ifndef NETPROTO_DEFAULT
70+
# define NETPROTO_DEFAULT NET_NFS
71+
#endif
72+
6973
static char *netdev_name;
7074
static int netdev_sock = -1;
7175
static int netdev_opens;
@@ -304,7 +308,7 @@ net_getparams(int sock)
304308
return (EIO);
305309
}
306310
exit:
307-
if ((rootaddr = net_parse_rootpath()) != INADDR_NONE)
311+
if ((rootaddr = net_parse_rootpath()) != htonl(INADDR_NONE))
308312
rootip.s_addr = rootaddr;
309313

310314
DEBUG_PRINTF(1,("%s: proto: %d\n", __func__, netproto));
@@ -355,7 +359,7 @@ is_tftp(void)
355359
* Parses the rootpath if present
356360
*
357361
* The rootpath format can be in the form
358-
* <scheme>://ip/path
362+
* <scheme>://ip[:port]/path
359363
* <scheme>:/path
360364
*
361365
* For compatibility with previous behaviour it also accepts as an NFS scheme
@@ -370,10 +374,10 @@ is_tftp(void)
370374
uint32_t
371375
net_parse_rootpath(void)
372376
{
373-
n_long addr = htonl(INADDR_NONE);
377+
n_long addr = 0;
374378
size_t i;
375379
char ip[FNAME_SIZE];
376-
char *ptr, *val;
380+
char *ptr, *portp, *val;
377381

378382
netproto = NET_NONE;
379383

@@ -388,7 +392,7 @@ net_parse_rootpath(void)
388392
ptr = rootpath;
389393
/* Fallback for compatibility mode */
390394
if (netproto == NET_NONE) {
391-
netproto = NET_NFS;
395+
netproto = NETPROTO_DEFAULT;
392396
(void)strsep(&ptr, ":");
393397
if (ptr != NULL) {
394398
addr = inet_addr(rootpath);
@@ -401,23 +405,29 @@ net_parse_rootpath(void)
401405
if (*ptr == '/') {
402406
/* we are in the form <scheme>://, we do expect an ip */
403407
ptr++;
404-
/*
405-
* XXX when http will be there we will need to check for
406-
* a port, but right now we do not need it yet
407-
*/
408+
portp = val = strchr(ptr, ':');
409+
if (val != NULL) {
410+
val++;
411+
rootport = strtol(val, NULL, 10);
412+
}
408413
val = strchr(ptr, '/');
409414
if (val != NULL) {
415+
if (portp == NULL)
416+
portp = val;
410417
snprintf(ip, sizeof(ip), "%.*s",
411-
(int)((uintptr_t)val - (uintptr_t)ptr),
418+
(int)(portp - ptr),
412419
ptr);
413420
addr = inet_addr(ip);
421+
DEBUG_PRINTF(1,("ip=%s addr=%#x\n",
422+
ip, addr));
414423
bcopy(val, rootpath, strlen(val) + 1);
415424
}
416425
} else {
417426
ptr--;
418427
bcopy(ptr, rootpath, strlen(ptr) + 1);
419428
}
420429
}
421-
430+
if (addr == 0)
431+
addr = htonl(INADDR_NONE);
422432
return (addr);
423433
}

stand/defs.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ LOADER_INTERP?=${LOADER_DEFAULT_INTERP}
207207
# Make sure we use the machine link we're about to create
208208
CFLAGS+=-I.
209209

210+
.include "${BOOTSRC}/veriexec.mk"
211+
210212
all: ${PROG}
211213

212214
CLEANFILES+= teken_state.h

stand/libsa/globals.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
u_char bcea[6] = BA; /* broadcast ethernet address */
1818

1919
char rootpath[FNAME_SIZE] = "/"; /* root mount path */
20+
int rootport; /* port for rootpath server */
2021
char bootfile[FNAME_SIZE]; /* bootp says to boot this */
2122
char hostname[FNAME_SIZE]; /* our hostname */
2223
int hostnamelen;

stand/libsa/libsa.3

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -781,6 +781,10 @@ The same as
781781
but for
782782
.Xr bzip2 1 Ns -compressed
783783
files.
784+
.It Va pkgfs_fsops
785+
File access from a tar file typically streamed via TFTP.
786+
The order of files in the tar file must match the order they are
787+
to be consumed as rewind is not practical.
784788
.El
785789
.Pp
786790
The array of

stand/libsa/net.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ enum net_proto {
7575

7676
extern u_char bcea[6];
7777
extern char rootpath[FNAME_SIZE];
78+
extern int rootport;
7879
extern char bootfile[FNAME_SIZE];
7980
extern char hostname[FNAME_SIZE];
8081
extern int hostnamelen;

0 commit comments

Comments
 (0)