Skip to content

Commit df6f280

Browse files
Philipp Rudotorvalds
authored andcommitted
kernel/kexec_file.c: move purgatories sha256 to common code
The code to verify the new kernels sha digest is applicable for all architectures. Move it to common code. One problem is the string.c implementation on x86. Currently sha256 includes x86/boot/string.h which defines memcpy and memset to be gcc builtins. By moving the sha256 implementation to common code and changing the include to linux/string.h both functions are no longer defined. Thus definitions have to be provided in x86/purgatory/string.c Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Philipp Rudo <[email protected]> Acked-by: Dave Young <[email protected]> Cc: AKASHI Takahiro <[email protected]> Cc: Eric Biederman <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Martin Schwidefsky <[email protected]> Cc: Michael Ellerman <[email protected]> Cc: Thiago Jung Bauermann <[email protected]> Cc: Vivek Goyal <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 3be3f61 commit df6f280

File tree

5 files changed

+28
-4
lines changed

5 files changed

+28
-4
lines changed

arch/x86/purgatory/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ purgatory-y := purgatory.o stack.o setup-x86_$(BITS).o sha256.o entry64.o string
66
targets += $(purgatory-y)
77
PURGATORY_OBJS = $(addprefix $(obj)/,$(purgatory-y))
88

9+
$(obj)/sha256.o: $(srctree)/lib/sha256.c
10+
$(call if_changed_rule,cc_o_c)
11+
912
LDFLAGS_purgatory.ro := -e purgatory_start -r --no-undefined -nostdlib -z nodefaultlib
1013
targets += purgatory.ro
1114

arch/x86/purgatory/purgatory.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
*/
1212

1313
#include <linux/bug.h>
14+
#include <linux/sha256.h>
1415
#include <asm/purgatory.h>
1516

16-
#include "sha256.h"
1717
#include "../boot/string.h"
1818

1919
unsigned long purgatory_backup_dest __section(.kexec-purgatory);

arch/x86/purgatory/string.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,16 @@
1010
* Version 2. See the file COPYING for more details.
1111
*/
1212

13+
#include <linux/types.h>
14+
1315
#include "../boot/string.c"
16+
17+
void *memcpy(void *dst, const void *src, size_t len)
18+
{
19+
return __builtin_memcpy(dst, src, len);
20+
}
21+
22+
void *memset(void *dst, int c, size_t len)
23+
{
24+
return __builtin_memset(dst, c, len);
25+
}

arch/x86/purgatory/sha256.h renamed to include/linux/sha256.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,18 @@
1313
#include <linux/types.h>
1414
#include <crypto/sha.h>
1515

16+
/*
17+
* Stand-alone implementation of the SHA256 algorithm. It is designed to
18+
* have as little dependencies as possible so it can be used in the
19+
* kexec_file purgatory. In other cases you should use the implementation in
20+
* crypto/.
21+
*
22+
* For details see lib/sha256.c
23+
*/
24+
1625
extern int sha256_init(struct sha256_state *sctx);
1726
extern int sha256_update(struct sha256_state *sctx, const u8 *input,
18-
unsigned int length);
27+
unsigned int length);
1928
extern int sha256_final(struct sha256_state *sctx, u8 *hash);
2029

2130
#endif /* SHA256_H */

arch/x86/purgatory/sha256.c renamed to lib/sha256.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
*/
1717

1818
#include <linux/bitops.h>
19+
#include <linux/sha256.h>
20+
#include <linux/string.h>
1921
#include <asm/byteorder.h>
20-
#include "sha256.h"
21-
#include "../boot/string.h"
2222

2323
static inline u32 Ch(u32 x, u32 y, u32 z)
2424
{

0 commit comments

Comments
 (0)