Skip to content

Commit ff2e185

Browse files
nathanlynchmpe
authored andcommitted
powerpc/pseries: Enforce hcall result buffer validity and size
plpar_hcall(), plpar_hcall9(), and related functions expect callers to provide valid result buffers of certain minimum size. Currently this is communicated only through comments in the code and the compiler has no idea. For example, if I write a bug like this: long retbuf[PLPAR_HCALL_BUFSIZE]; // should be PLPAR_HCALL9_BUFSIZE plpar_hcall9(H_ALLOCATE_VAS_WINDOW, retbuf, ...); This compiles with no diagnostics emitted, but likely results in stack corruption at runtime when plpar_hcall9() stores results past the end of the array. (To be clear this is a contrived example and I have not found a real instance yet.) To make this class of error less likely, we can use explicitly-sized array parameters instead of pointers in the declarations for the hcall APIs. When compiled with -Warray-bounds[1], the code above now provokes a diagnostic like this: error: array argument is too small; is of size 32, callee requires at least 72 [-Werror,-Warray-bounds] 60 | plpar_hcall9(H_ALLOCATE_VAS_WINDOW, retbuf, | ^ ~~~~~~ [1] Enabled for LLVM builds but not GCC for now. See commit 0da6e5f ("gcc: disable '-Warray-bounds' for gcc-13 too") and related changes. Signed-off-by: Nathan Lynch <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://msgid.link/[email protected]
1 parent 4ccae23 commit ff2e185

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arch/powerpc/include/asm/hvcall.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ long plpar_hcall_norets_notrace(unsigned long opcode, ...);
524524
* Used for all but the craziest of phyp interfaces (see plpar_hcall9)
525525
*/
526526
#define PLPAR_HCALL_BUFSIZE 4
527-
long plpar_hcall(unsigned long opcode, unsigned long *retbuf, ...);
527+
long plpar_hcall(unsigned long opcode, unsigned long retbuf[static PLPAR_HCALL_BUFSIZE], ...);
528528

529529
/**
530530
* plpar_hcall_raw: - Make a hypervisor call without calculating hcall stats
@@ -538,7 +538,7 @@ long plpar_hcall(unsigned long opcode, unsigned long *retbuf, ...);
538538
* plpar_hcall, but plpar_hcall_raw works in real mode and does not
539539
* calculate hypervisor call statistics.
540540
*/
541-
long plpar_hcall_raw(unsigned long opcode, unsigned long *retbuf, ...);
541+
long plpar_hcall_raw(unsigned long opcode, unsigned long retbuf[static PLPAR_HCALL_BUFSIZE], ...);
542542

543543
/**
544544
* plpar_hcall9: - Make a pseries hypervisor call with up to 9 return arguments
@@ -549,8 +549,8 @@ long plpar_hcall_raw(unsigned long opcode, unsigned long *retbuf, ...);
549549
* PLPAR_HCALL9_BUFSIZE to size the return argument buffer.
550550
*/
551551
#define PLPAR_HCALL9_BUFSIZE 9
552-
long plpar_hcall9(unsigned long opcode, unsigned long *retbuf, ...);
553-
long plpar_hcall9_raw(unsigned long opcode, unsigned long *retbuf, ...);
552+
long plpar_hcall9(unsigned long opcode, unsigned long retbuf[static PLPAR_HCALL9_BUFSIZE], ...);
553+
long plpar_hcall9_raw(unsigned long opcode, unsigned long retbuf[static PLPAR_HCALL9_BUFSIZE], ...);
554554

555555
/* pseries hcall tracing */
556556
extern struct static_key hcall_tracepoint_key;

0 commit comments

Comments
 (0)