Skip to content

Commit 9a93db3

Browse files
committed
[pxe] Provide PXENV_FILE_EXIT_HOOK only for ipxelinux.0 builds
PXENV_FILE_EXIT_HOOK is designed to allow ipxelinux.0 to unload both the iPXE and pxelinux components without affecting the underlying PXE stack. Unfortunately, it causes unexpected behaviour in other situations, such as when loading a non-embedded pxelinux.0 via undionly.kpxe. For example: PXE ROM -> undionly.kpxe -> pxelinux.0 -> chain.c32 to boot hd0 would cause control to return to iPXE instead of booting from the hard disk. In some cases, this would result in a harmless but confusing "No more network devices" message; in other cases stranger things would happen, such as being returned to the iPXE shell prompt. The fundamental problem is that when pxelinux detects PXENV_FILE_EXIT_HOOK, it may attempt to specify an exit hook and then exit back to iPXE, assuming that iPXE will in turn exit cleanly via the specified exit hook. This is not a valid assumption in the general case, since the action of exiting back to iPXE does not directly cause iPXE to exit itself. (In the specific case of ipxelinux.0, this will work since the embedded script exits as soon as pxelinux.0 exits.) Fix the unexpected behaviour in the non-ipxelinux.0 cases by including support for PXENV_FILE_EXIT_HOOK only when using a new .kkkpxe format. The ipxelinux.0 build process should therefore now use undionly.kkkpxe instead of undionly.kkpxe. Signed-off-by: Michael Brown <mcb30@ipxe.org>
1 parent fa410e0 commit 9a93db3

6 files changed

Lines changed: 118 additions & 53 deletions

File tree

src/arch/i386/Makefile.pcbios

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ MEDIA += mrom
1919
MEDIA += pxe
2020
MEDIA += kpxe
2121
MEDIA += kkpxe
22+
MEDIA += kkkpxe
2223
MEDIA += lkrn
2324
MEDIA += dsk
2425
MEDIA += nbi

src/arch/i386/include/pxe_api.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1511,6 +1511,12 @@ typedef struct s_PXENV_UNDI_ISR PXENV_UNDI_ISR_t;
15111511
* @{
15121512
*/
15131513

1514+
/** Minimum possible opcode used within PXE FILE API */
1515+
#define PXENV_FILE_MIN 0x00e0
1516+
1517+
/** Minimum possible opcode used within PXE FILE API */
1518+
#define PXENV_FILE_MAX 0x00ef
1519+
15141520
/** @defgroup pxenv_file_open PXENV_FILE_OPEN
15151521
*
15161522
* FILE OPEN
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/** @file
2+
*
3+
* PXE exit hook
4+
*
5+
*/
6+
7+
/*
8+
* Copyright (C) 2010 Shao Miller <shao.miller@yrdsb.edu.on.ca>.
9+
*
10+
* This program is free software; you can redistribute it and/or
11+
* modify it under the terms of the GNU General Public License as
12+
* published by the Free Software Foundation; either version 2 of the
13+
* License, or any later version.
14+
*
15+
* This program is distributed in the hope that it will be useful, but
16+
* WITHOUT ANY WARRANTY; without even the implied warranty of
17+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18+
* General Public License for more details.
19+
*
20+
* You should have received a copy of the GNU General Public License
21+
* along with this program; if not, write to the Free Software
22+
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23+
*/
24+
25+
FILE_LICENCE ( GPL2_OR_LATER );
26+
27+
#include <stdint.h>
28+
#include <realmode.h>
29+
#include <pxe.h>
30+
31+
/** PXE exit hook */
32+
extern segoff_t __data16 ( pxe_exit_hook );
33+
#define pxe_exit_hook __use_data16 ( pxe_exit_hook )
34+
35+
/**
36+
* FILE EXIT HOOK
37+
*
38+
* @v file_exit_hook Pointer to a struct
39+
* s_PXENV_FILE_EXIT_HOOK
40+
* @v s_PXENV_FILE_EXIT_HOOK::Hook SEG16:OFF16 to jump to
41+
* @ret #PXENV_EXIT_SUCCESS Successfully set hook
42+
* @ret #PXENV_EXIT_FAILURE We're not an NBP build
43+
* @ret s_PXENV_FILE_EXIT_HOOK::Status PXE status code
44+
*
45+
*/
46+
static PXENV_EXIT_t
47+
pxenv_file_exit_hook ( struct s_PXENV_FILE_EXIT_HOOK *file_exit_hook ) {
48+
DBG ( "PXENV_FILE_EXIT_HOOK" );
49+
50+
/* We'll jump to the specified SEG16:OFF16 during exit */
51+
pxe_exit_hook.segment = file_exit_hook->Hook.segment;
52+
pxe_exit_hook.offset = file_exit_hook->Hook.offset;
53+
file_exit_hook->Status = PXENV_STATUS_SUCCESS;
54+
return PXENV_EXIT_SUCCESS;
55+
}
56+
57+
/** PXE file API */
58+
struct pxe_api_call pxe_file_api_exit_hook __pxe_api_call =
59+
PXE_API_CALL ( PXENV_FILE_EXIT_HOOK, pxenv_file_exit_hook,
60+
struct s_PXENV_FILE_EXIT_HOOK );

src/arch/i386/interface/pxe/pxe_file.c

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
/*
1818
* Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
19-
* Portions (C) 2010 Shao Miller <shao.miller@yrdsb.edu.on.ca>.
20-
* [PXE exit hook logic]
2119
*
2220
* This program is free software; you can redistribute it and/or
2321
* modify it under the terms of the GNU General Public License as
@@ -234,9 +232,6 @@ static PXENV_EXIT_t pxenv_file_exec ( struct s_PXENV_FILE_EXEC *file_exec ) {
234232
return PXENV_EXIT_SUCCESS;
235233
}
236234

237-
segoff_t __data16 ( pxe_exit_hook ) = { 0, 0 };
238-
#define pxe_exit_hook __use_data16 ( pxe_exit_hook )
239-
240235
/**
241236
* FILE API CHECK
242237
*
@@ -253,57 +248,40 @@ segoff_t __data16 ( pxe_exit_hook ) = { 0, 0 };
253248
*/
254249
static PXENV_EXIT_t
255250
pxenv_file_api_check ( struct s_PXENV_FILE_API_CHECK *file_api_check ) {
251+
struct pxe_api_call *call;
252+
unsigned int mask = 0;
253+
unsigned int offset;
254+
256255
DBG ( "PXENV_FILE_API_CHECK" );
257256

257+
/* Check for magic value */
258258
if ( file_api_check->Magic != 0x91d447b2 ) {
259259
file_api_check->Status = PXENV_STATUS_BAD_FUNC;
260260
return PXENV_EXIT_FAILURE;
261-
} else if ( file_api_check->Size <
262-
sizeof(struct s_PXENV_FILE_API_CHECK) ) {
261+
}
262+
263+
/* Check for required parameter size */
264+
if ( file_api_check->Size < sizeof ( *file_api_check ) ) {
263265
file_api_check->Status = PXENV_STATUS_OUT_OF_RESOURCES;
264266
return PXENV_EXIT_FAILURE;
265-
} else {
266-
file_api_check->Status = PXENV_STATUS_SUCCESS;
267-
file_api_check->Size = sizeof(struct s_PXENV_FILE_API_CHECK);
268-
file_api_check->Magic = 0xe9c17b20;
269-
file_api_check->Provider = 0x45585067; /* "iPXE" */
270-
file_api_check->APIMask = 0x0000007f; /* Functions e0-e6 */
271-
/* Check to see if we have a PXE exit hook */
272-
if ( pxe_exit_hook.segment | pxe_exit_hook.offset )
273-
/* Function e7, also */
274-
file_api_check->APIMask |= 0x00000080;
275-
file_api_check->Flags = 0; /* None defined */
276-
return PXENV_EXIT_SUCCESS;
277267
}
278-
}
279268

280-
/**
281-
* FILE EXIT HOOK
282-
*
283-
* @v file_exit_hook Pointer to a struct
284-
* s_PXENV_FILE_EXIT_HOOK
285-
* @v s_PXENV_FILE_EXIT_HOOK::Hook SEG16:OFF16 to jump to
286-
* @ret #PXENV_EXIT_SUCCESS Successfully set hook
287-
* @ret #PXENV_EXIT_FAILURE We're not an NBP build
288-
* @ret s_PXENV_FILE_EXIT_HOOK::Status PXE status code
289-
*
290-
*/
291-
static PXENV_EXIT_t
292-
pxenv_file_exit_hook ( struct s_PXENV_FILE_EXIT_HOOK *file_exit_hook ) {
293-
DBG ( "PXENV_FILE_EXIT_HOOK" );
294-
295-
/* Check to see if we have a PXE exit hook */
296-
if ( pxe_exit_hook.segment | pxe_exit_hook.offset ) {
297-
/* We'll jump to the specified SEG16:OFF16 during exit */
298-
pxe_exit_hook.segment = file_exit_hook->Hook.segment;
299-
pxe_exit_hook.offset = file_exit_hook->Hook.offset;
300-
file_exit_hook->Status = PXENV_STATUS_SUCCESS;
301-
return PXENV_EXIT_SUCCESS;
269+
/* Determine supported calls */
270+
for_each_table_entry ( call, PXE_API_CALLS ) {
271+
offset = ( call->opcode - PXENV_FILE_MIN );
272+
if ( offset <= ( PXENV_FILE_MAX - PXENV_FILE_MIN ) )
273+
mask |= ( 1 << offset );
302274
}
303275

304-
DBG ( " not NBP" );
305-
file_exit_hook->Status = PXENV_STATUS_UNSUPPORTED;
306-
return PXENV_EXIT_FAILURE;
276+
/* Fill in parameters */
277+
file_api_check->Size = sizeof ( *file_api_check );
278+
file_api_check->Magic = 0xe9c17b20;
279+
file_api_check->Provider = 0x45585067; /* "iPXE" */
280+
file_api_check->APIMask = mask;
281+
file_api_check->Flags = 0; /* None defined */
282+
283+
file_api_check->Status = PXENV_STATUS_SUCCESS;
284+
return PXENV_EXIT_SUCCESS;
307285
}
308286

309287
/** PXE file API */
@@ -322,6 +300,4 @@ struct pxe_api_call pxe_file_api[] __pxe_api_call = {
322300
struct s_PXENV_FILE_EXEC ),
323301
PXE_API_CALL ( PXENV_FILE_API_CHECK, pxenv_file_api_check,
324302
struct s_PXENV_FILE_API_CHECK ),
325-
PXE_API_CALL ( PXENV_FILE_EXIT_HOOK, pxenv_file_exit_hook,
326-
struct s_PXENV_FILE_EXIT_HOOK ),
327303
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*****************************************************************************
2+
* PXE prefix that keeps the whole PXE stack present and provides an exit hook
3+
*
4+
* This prefix is essentially intended solely for the case of ipxelinux.0
5+
*****************************************************************************
6+
*/
7+
8+
FILE_LICENCE ( GPL2_OR_LATER )
9+
10+
/* Since we have the whole stack, we can use cached DHCP information */
11+
REQUIRE_OBJECT ( pxeparent_dhcp )
12+
13+
/* Provide the PXENV_FILE_EXIT_HOOK API call */
14+
REQUIRE_OBJECT ( pxe_exit_hook )
15+
16+
#define PXELOADER_KEEP_UNDI
17+
#define PXELOADER_KEEP_PXE
18+
#define _pxe_start _kkkpxe_start
19+
#include "pxeprefix.S"

src/arch/i386/prefix/pxeprefix.S

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,11 +721,7 @@ run_ipxe:
721721
.section ".text16", "ax", @progbits
722722
1:
723723
/* Update the exit hook */
724-
movw %cs,pxe_exit_hook+2
725-
push %ax
726-
mov $2f,%ax
727-
mov %ax,pxe_exit_hook
728-
pop %ax
724+
movw %cs, ( pxe_exit_hook + 2 )
729725

730726
/* Run main program */
731727
pushl $main
@@ -743,7 +739,14 @@ run_ipxe:
743739
/* Jump to hook if applicable */
744740
ljmpw *pxe_exit_hook
745741

746-
2: /* Check PXE stack magic */
742+
.section ".data16", "aw", @progbits
743+
.globl pxe_exit_hook
744+
pxe_exit_hook:
745+
.word exit_ipxe, 0
746+
.previous
747+
748+
exit_ipxe:
749+
/* Check PXE stack magic */
747750
popl %eax
748751
cmpl $STACK_MAGIC, %eax
749752
jne 1f

0 commit comments

Comments
 (0)