Selaa lähdekoodia

[int13con] Avoid overwriting random portions of SAN boot disks

The INT13 console type (CONSOLE_INT13) autodetects at initialisation
time a magic partition to be used for logging iPXE console output.  If
the INT13 drive number mapping is subsequently changed (e.g. because
iPXE was used to perform a SAN boot), then the console logging output
will be written to the incorrect disk.

Fix by recording the INT13 vector at initialisation time, and using
this original vector to emulate INT13 calls for all subsequent
accesses.  This should be robust against drive remapping performed
either by ourselves or by another bootloader (e.g. a chainloaded
undionly.kpxe which then performs a SAN boot).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 vuotta sitten
vanhempi
commit
c73af29fe2
1 muutettua tiedostoa jossa 17 lisäystä ja 2 poistoa
  1. 17
    2
      src/arch/x86/interface/pcbios/int13con.c

+ 17
- 2
src/arch/x86/interface/pcbios/int13con.c Näytä tiedosto

62
 /** Log partition magic signature */
62
 /** Log partition magic signature */
63
 #define INT13CON_MAGIC "iPXE LOG\n\n"
63
 #define INT13CON_MAGIC "iPXE LOG\n\n"
64
 
64
 
65
+/** Original INT13 vector */
66
+static struct segoff __bss16 ( int13con_vector );
67
+#define int13con_vector __use_data16 ( int13con_vector )
68
+
65
 /** Sector buffer */
69
 /** Sector buffer */
66
 static uint8_t __bss16_array ( int13con_buffer, [INT13_BLKSIZE] );
70
 static uint8_t __bss16_array ( int13con_buffer, [INT13_BLKSIZE] );
67
 #define int13con_buffer __use_data16 ( int13con_buffer )
71
 #define int13con_buffer __use_data16 ( int13con_buffer )
101
 	int13con_address.buffer.offset = __from_data16 ( int13con_buffer );
105
 	int13con_address.buffer.offset = __from_data16 ( int13con_buffer );
102
 	int13con_address.lba = lba;
106
 	int13con_address.lba = lba;
103
 
107
 
104
-	/* Issue INT13 */
105
-	__asm__ ( REAL_CODE ( "int $0x13\n\t" )
108
+	/* Emulate INT13 via original vector.  We do this since iPXE
109
+	 * (or another subsequent bootloader) may hook INT13 and remap
110
+	 * drive numbers.
111
+	 */
112
+	__asm__ ( REAL_CODE ( "pushfw\n\t"
113
+			      "cli\n\t"
114
+			      "lcall *int13con_vector\n\t" )
106
 		  : "=a" ( error )
115
 		  : "=a" ( error )
107
 		  : "0" ( op << 8 ), "d" ( INT13CON_DRIVE ),
116
 		  : "0" ( op << 8 ), "d" ( INT13CON_DRIVE ),
108
 		    "S" ( __from_data16 ( &int13con_address ) ) );
117
 		    "S" ( __from_data16 ( &int13con_address ) ) );
261
 		return;
270
 		return;
262
 	}
271
 	}
263
 
272
 
273
+	/* Store original INT13 vector */
274
+	copy_from_real ( &int13con_vector, 0, ( 0x13 * 4 ),
275
+			 sizeof ( int13con_vector ) );
276
+	DBG ( "INT13CON using original INT13 vector %04x:%04x\n",
277
+	      int13con_vector.segment, int13con_vector.offset );
278
+
264
 	/* Locate log partition */
279
 	/* Locate log partition */
265
 	if ( ( rc = int13con_find() ) != 0)
280
 	if ( ( rc = int13con_find() ) != 0)
266
 		return;
281
 		return;

Loading…
Peruuta
Tallenna