forked from mirrors/linux
		
	Patch series "Allow to kexec with initramfs larger than 2G", v2. Currently, the largest initramfs that is supported by kexec_file_load() syscall is 2G. This is because kernel_read_file() returns int, and is limited to INT_MAX or 2G. On the other hand, there are kexec based boot loaders (i.e. u-root), that may need to boot netboot images that might be larger than 2G. The first patch changes the return type from int to ssize_t in kernel_read_file* functions. The second patch increases the maximum initramfs file size to 4G. Tested: verified that can kexec_file_load() works with 4G initramfs on x86_64. This patch (of 2): Currently, the maximum file size that is supported is 2G. This may be too small in some cases. For example, kexec_file_load() system call loads initramfs. In some netboot cases initramfs can be rather large. Allow to use up-to ssize_t bytes. The callers still can limit the maximum file size via buf_size. Link: https://lkml.kernel.org/r/20220527025535.3953665-1-pasha.tatashin@soleen.com Link: https://lkml.kernel.org/r/20220527025535.3953665-2-pasha.tatashin@soleen.com Signed-off-by: Pasha Tatashin <pasha.tatashin@soleen.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Baoquan He <bhe@redhat.com> Cc: "Eric W. Biederman" <ebiederm@xmission.com> Cc: Greg Thelen <gthelen@google.com> Cc: Sasha Levin <sashal@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
		
			
				
	
	
		
			55 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
	
		
			1.6 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
/* SPDX-License-Identifier: GPL-2.0 */
 | 
						|
#ifndef _LINUX_KERNEL_READ_FILE_H
 | 
						|
#define _LINUX_KERNEL_READ_FILE_H
 | 
						|
 | 
						|
#include <linux/file.h>
 | 
						|
#include <linux/types.h>
 | 
						|
 | 
						|
/* This is a list of *what* is being read, not *how* nor *where*. */
 | 
						|
#define __kernel_read_file_id(id) \
 | 
						|
	id(UNKNOWN, unknown)		\
 | 
						|
	id(FIRMWARE, firmware)		\
 | 
						|
	id(MODULE, kernel-module)		\
 | 
						|
	id(KEXEC_IMAGE, kexec-image)		\
 | 
						|
	id(KEXEC_INITRAMFS, kexec-initramfs)	\
 | 
						|
	id(POLICY, security-policy)		\
 | 
						|
	id(X509_CERTIFICATE, x509-certificate)	\
 | 
						|
	id(MAX_ID, )
 | 
						|
 | 
						|
#define __fid_enumify(ENUM, dummy) READING_ ## ENUM,
 | 
						|
#define __fid_stringify(dummy, str) #str,
 | 
						|
 | 
						|
enum kernel_read_file_id {
 | 
						|
	__kernel_read_file_id(__fid_enumify)
 | 
						|
};
 | 
						|
 | 
						|
static const char * const kernel_read_file_str[] = {
 | 
						|
	__kernel_read_file_id(__fid_stringify)
 | 
						|
};
 | 
						|
 | 
						|
static inline const char *kernel_read_file_id_str(enum kernel_read_file_id id)
 | 
						|
{
 | 
						|
	if ((unsigned int)id >= READING_MAX_ID)
 | 
						|
		return kernel_read_file_str[READING_UNKNOWN];
 | 
						|
 | 
						|
	return kernel_read_file_str[id];
 | 
						|
}
 | 
						|
 | 
						|
ssize_t kernel_read_file(struct file *file, loff_t offset,
 | 
						|
			 void **buf, size_t buf_size,
 | 
						|
			 size_t *file_size,
 | 
						|
			 enum kernel_read_file_id id);
 | 
						|
ssize_t kernel_read_file_from_path(const char *path, loff_t offset,
 | 
						|
				   void **buf, size_t buf_size,
 | 
						|
				   size_t *file_size,
 | 
						|
				   enum kernel_read_file_id id);
 | 
						|
ssize_t kernel_read_file_from_path_initns(const char *path, loff_t offset,
 | 
						|
					  void **buf, size_t buf_size,
 | 
						|
					  size_t *file_size,
 | 
						|
					  enum kernel_read_file_id id);
 | 
						|
ssize_t kernel_read_file_from_fd(int fd, loff_t offset,
 | 
						|
				 void **buf, size_t buf_size,
 | 
						|
				 size_t *file_size,
 | 
						|
				 enum kernel_read_file_id id);
 | 
						|
 | 
						|
#endif /* _LINUX_KERNEL_READ_FILE_H */
 |