Merge upstream changes as of April 29th

This commit is contained in:
Michael Marineau 2015-07-31 15:41:48 -07:00
commit c7c750ecc2
267 changed files with 6019 additions and 1963 deletions

View file

@ -205,13 +205,16 @@ grub_crypto_ecb_decrypt (grub_crypto_cipher_handle_t cipher,
{
const grub_uint8_t *inptr, *end;
grub_uint8_t *outptr;
grub_size_t blocksize;
if (!cipher->cipher->decrypt)
return GPG_ERR_NOT_SUPPORTED;
if (size % cipher->cipher->blocksize != 0)
blocksize = cipher->cipher->blocksize;
if (blocksize == 0 || (((blocksize - 1) & blocksize) != 0)
|| ((size & (blocksize - 1)) != 0))
return GPG_ERR_INV_ARG;
end = (const grub_uint8_t *) in + size;
for (inptr = in, outptr = out; inptr < end;
inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize)
inptr += blocksize, outptr += blocksize)
cipher->cipher->decrypt (cipher->ctx, outptr, inptr);
return GPG_ERR_NO_ERROR;
}
@ -222,13 +225,16 @@ grub_crypto_ecb_encrypt (grub_crypto_cipher_handle_t cipher,
{
const grub_uint8_t *inptr, *end;
grub_uint8_t *outptr;
grub_size_t blocksize;
if (!cipher->cipher->encrypt)
return GPG_ERR_NOT_SUPPORTED;
if (size % cipher->cipher->blocksize != 0)
blocksize = cipher->cipher->blocksize;
if (blocksize == 0 || (((blocksize - 1) & blocksize) != 0)
|| ((size & (blocksize - 1)) != 0))
return GPG_ERR_INV_ARG;
end = (const grub_uint8_t *) in + size;
for (inptr = in, outptr = out; inptr < end;
inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize)
inptr += blocksize, outptr += blocksize)
cipher->cipher->encrypt (cipher->ctx, outptr, inptr);
return GPG_ERR_NO_ERROR;
}
@ -241,20 +247,23 @@ grub_crypto_cbc_encrypt (grub_crypto_cipher_handle_t cipher,
grub_uint8_t *outptr;
const grub_uint8_t *inptr, *end;
void *iv;
if (!cipher->cipher->decrypt)
grub_size_t blocksize;
if (!cipher->cipher->encrypt)
return GPG_ERR_NOT_SUPPORTED;
if (size % cipher->cipher->blocksize != 0)
blocksize = cipher->cipher->blocksize;
if (blocksize == 0 || (((blocksize - 1) & blocksize) != 0)
|| ((size & (blocksize - 1)) != 0))
return GPG_ERR_INV_ARG;
end = (const grub_uint8_t *) in + size;
iv = iv_in;
for (inptr = in, outptr = out; inptr < end;
inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize)
inptr += blocksize, outptr += blocksize)
{
grub_crypto_xor (outptr, inptr, iv, cipher->cipher->blocksize);
grub_crypto_xor (outptr, inptr, iv, blocksize);
cipher->cipher->encrypt (cipher->ctx, outptr, outptr);
iv = outptr;
}
grub_memcpy (iv_in, iv, cipher->cipher->blocksize);
grub_memcpy (iv_in, iv, blocksize);
return GPG_ERR_NO_ERROR;
}
@ -266,20 +275,23 @@ grub_crypto_cbc_decrypt (grub_crypto_cipher_handle_t cipher,
const grub_uint8_t *inptr, *end;
grub_uint8_t *outptr;
grub_uint8_t ivt[GRUB_CRYPTO_MAX_CIPHER_BLOCKSIZE];
grub_size_t blocksize;
if (!cipher->cipher->decrypt)
return GPG_ERR_NOT_SUPPORTED;
if (size % cipher->cipher->blocksize != 0)
blocksize = cipher->cipher->blocksize;
if (blocksize == 0 || (((blocksize - 1) & blocksize) != 0)
|| ((size & (blocksize - 1)) != 0))
return GPG_ERR_INV_ARG;
if (cipher->cipher->blocksize > GRUB_CRYPTO_MAX_CIPHER_BLOCKSIZE)
if (blocksize > GRUB_CRYPTO_MAX_CIPHER_BLOCKSIZE)
return GPG_ERR_INV_ARG;
end = (const grub_uint8_t *) in + size;
for (inptr = in, outptr = out; inptr < end;
inptr += cipher->cipher->blocksize, outptr += cipher->cipher->blocksize)
inptr += blocksize, outptr += blocksize)
{
grub_memcpy (ivt, inptr, cipher->cipher->blocksize);
grub_memcpy (ivt, inptr, blocksize);
cipher->cipher->decrypt (cipher->ctx, outptr, inptr);
grub_crypto_xor (outptr, outptr, iv, cipher->cipher->blocksize);
grub_memcpy (iv, ivt, cipher->cipher->blocksize);
grub_crypto_xor (outptr, outptr, iv, blocksize);
grub_memcpy (iv, ivt, blocksize);
}
return GPG_ERR_NO_ERROR;
}

74
grub-core/lib/division.c Normal file
View file

@ -0,0 +1,74 @@
/*
* GRUB -- GRand Unified Bootloader
* Copyright (C) 2015 Free Software Foundation, Inc.
*
* GRUB is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* GRUB is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
*/
#include <grub/misc.h>
#include <grub/dl.h>
GRUB_MOD_LICENSE ("GPLv3+");
static grub_uint64_t
abs64(grub_int64_t a)
{
return a > 0 ? a : -a;
}
grub_int64_t
grub_divmod64s (grub_int64_t n,
grub_int64_t d,
grub_int64_t *ro)
{
grub_uint64_t ru;
grub_int64_t q, r;
q = grub_divmod64 (abs64(n), abs64(d), &ru);
r = ru;
/* Now: |n| = |d| * q + r */
if (n < 0)
{
/* -|n| = |d| * (-q) + (-r) */
q = -q;
r = -r;
}
/* Now: n = |d| * q + r */
if (d < 0)
{
/* n = (-|d|) * (-q) + r */
q = -q;
}
/* Now: n = d * q + r */
if (ro)
*ro = r;
return q;
}
grub_uint32_t
grub_divmod32 (grub_uint32_t n, grub_uint32_t d, grub_uint32_t *ro)
{
grub_uint64_t q, r;
q = grub_divmod64 (n, d, &r);
*ro = r;
return q;
}
grub_int32_t
grub_divmod32s (grub_int32_t n, grub_int32_t d, grub_int32_t *ro)
{
grub_int64_t q, r;
q = grub_divmod64s (n, d, &r);
*ro = r;
return q;
}

View file

@ -664,6 +664,7 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
{
case TYPE_FILE_NO_CONSUME:
hold_arg = 1;
/* Fallthrough. */
case TYPE_PARTITION:
case TYPE_FILE:
args[i] = adjust_file (curarg, curarglen);

View file

@ -17,11 +17,13 @@
*/
#include <grub/symbol.h>
#include <grub/cpu/kernel.h>
.p2align 4 /* force 16-byte alignment */
.set noreorder
.set nomacro
mips_attributes
VARIABLE (grub_relocator_forward_start)
move $a0, $9

View file

@ -52,7 +52,7 @@ grub_crypto_pbkdf2 (const struct gcry_md_spec *md,
grub_uint8_t *tmp;
grub_size_t tmplen = Slen + 4;
if (md->mdlen > GRUB_CRYPTO_MAX_MDLEN)
if (md->mdlen > GRUB_CRYPTO_MAX_MDLEN || md->mdlen == 0)
return GPG_ERR_INV_ARG;
if (c == 0)

View file

@ -42,21 +42,6 @@ strcasecmp (const char *s1, const char *s2)
return grub_strcasecmp (s1, s2);
}
#ifdef GRUB_UTIL
static inline void *
memcpy (void *dest, const void *src, grub_size_t n)
{
return grub_memcpy (dest, src, n);
}
static inline int
memcmp (const void *s1, const void *s2, grub_size_t n)
{
return grub_memcmp (s1, s2, n);
}
#endif
static inline void
bcopy (const void *src, void *dest, grub_size_t n)
{
@ -99,4 +84,9 @@ memchr (const void *s, int c, grub_size_t n)
return grub_memchr (s, c, n);
}
#define memcmp grub_memcmp
#define memcpy grub_memcpy
#define memmove grub_memmove
#define memset grub_memset
#endif

View file

@ -649,6 +649,8 @@ helptext (const char *line, grub_file_t file, struct syslinux_menu *menu)
grub_size_t helplen, alloclen = 0;
help = grub_strdup (line);
if (!help)
return grub_errno;
helplen = grub_strlen (line);
while ((grub_free (buf), buf = grub_file_getline (file)))
{
@ -682,6 +684,7 @@ helptext (const char *line, grub_file_t file, struct syslinux_menu *menu)
}
grub_free (buf);
grub_free (help);
return grub_errno;
}
@ -717,7 +720,7 @@ syslinux_parse_real (struct syslinux_menu *menu)
for (ptr3 = ptr2; grub_isspace (*ptr3) && *ptr3; ptr3++);
for (ptr4 = ptr3; !grub_isspace (*ptr4) && *ptr4; ptr4++);
for (ptr5 = ptr4; grub_isspace (*ptr5) && *ptr5; ptr5++);
for (i = 0; i < sizeof (commands) / sizeof (commands[0]); i++)
for (i = 0; i < ARRAY_SIZE(commands); i++)
if (grub_strlen (commands[i].name1) == (grub_size_t) (ptr2 - ptr1)
&& grub_strncasecmp (commands[i].name1, ptr1, ptr2 - ptr1) == 0
&& (commands[i].name2 == NULL
@ -726,7 +729,7 @@ syslinux_parse_real (struct syslinux_menu *menu)
&& grub_strncasecmp (commands[i].name2, ptr3, ptr4 - ptr3)
== 0)))
break;
if (i == sizeof (commands) / sizeof (commands[0]))
if (i == ARRAY_SIZE(commands))
{
if (sizeof ("text") - 1 == ptr2 - ptr1
&& grub_strncasecmp ("text", ptr1, ptr2 - ptr1) == 0
@ -836,6 +839,82 @@ simplify_filename (char *str)
*optr = '\0';
}
static grub_err_t
print_config (struct output_buffer *outbuf,
struct syslinux_menu *menu,
const char *filename, const char *basedir)
{
struct syslinux_menu *menuptr;
grub_err_t err = GRUB_ERR_NONE;
char *new_cwd = NULL;
char *new_target_cwd = NULL;
char *newname = NULL;
int depth = 0;
new_cwd = get_read_filename (menu, basedir);
if (!new_cwd)
{
err = grub_errno;
goto out;
}
new_target_cwd = get_target_filename (menu, basedir);
if (!new_target_cwd)
{
err = grub_errno;
goto out;
}
newname = get_read_filename (menu, filename);
if (!newname)
{
err = grub_errno;
goto out;
}
simplify_filename (newname);
print_string ("#");
print_file (outbuf, menu, filename, NULL);
print_string (" ");
print (outbuf, newname, grub_strlen (newname));
print_string (":\n");
for (menuptr = menu; menuptr; menuptr = menuptr->parent, depth++)
if (grub_strcmp (menuptr->filename, newname) == 0
|| depth > 20)
break;
if (menuptr)
{
print_string (" syslinux_configfile -r ");
print_file (outbuf, menu, "/", NULL);
print_string (" -c ");
print_file (outbuf, menu, basedir, NULL);
print_string (" ");
print_file (outbuf, menu, filename, NULL);
print_string ("\n");
}
else
{
err = config_file (outbuf, menu->root_read_directory,
menu->root_target_directory, new_cwd, new_target_cwd,
newname, menu, menu->flavour);
if (err == GRUB_ERR_FILE_NOT_FOUND
|| err == GRUB_ERR_BAD_FILENAME)
{
grub_errno = err = GRUB_ERR_NONE;
print_string ("# File ");
err = print (outbuf, newname, grub_strlen (newname));
if (err)
goto out;
print_string (" not found\n");
}
}
out:
grub_free (newname);
grub_free (new_cwd);
grub_free (new_target_cwd);
return err;
}
static grub_err_t
write_entry (struct output_buffer *outbuf,
struct syslinux_menu *menu,
@ -843,7 +922,12 @@ write_entry (struct output_buffer *outbuf,
{
grub_err_t err;
if (curentry->comments)
print (outbuf, curentry->comments, grub_strlen (curentry->comments));
{
err = print (outbuf, curentry->comments,
grub_strlen (curentry->comments));
if (err)
return err;
}
{
struct syslinux_say *say;
for (say = curentry->say; say && say->next; say = say->next);
@ -861,7 +945,6 @@ write_entry (struct output_buffer *outbuf,
case KERNEL_LINUX:
{
char *ptr;
char *cmdline;
char *initrd = NULL;
for (ptr = curentry->append; ptr && *ptr; ptr++)
if ((ptr == curentry->append || grub_isspace (ptr[-1]))
@ -871,31 +954,19 @@ write_entry (struct output_buffer *outbuf,
if (ptr && *ptr)
{
char *ptr2;
grub_size_t totlen = grub_strlen (curentry->append);
initrd = ptr + sizeof ("initrd=") - 1;
for (ptr2 = ptr; *ptr2 && !grub_isspace (*ptr2); ptr2++);
if (*ptr2)
{
*ptr2 = 0;
ptr2++;
}
cmdline = grub_malloc (totlen + 1 - (ptr2 - ptr));
if (!cmdline)
initrd = grub_strdup(ptr + sizeof ("initrd=") - 1);
if (!initrd)
return grub_errno;
grub_memcpy (cmdline, curentry->append, ptr - curentry->append);
grub_memcpy (cmdline + (ptr - curentry->append),
ptr2, totlen - (ptr2 - curentry->append));
*(cmdline + totlen - (ptr2 - ptr)) = 0;
for (ptr2 = initrd; *ptr2 && !grub_isspace (*ptr2); ptr2++);
*ptr2 = 0;
}
else
cmdline = curentry->append;
print_string (" if test x$grub_platform = xpc; then "
"linux_suffix=16; else linux_suffix= ; fi\n");
print_string (" linux$linux_suffix ");
print_file (outbuf, menu, curentry->kernel_file, NULL);
print_string (" ");
if (cmdline)
print (outbuf, cmdline, grub_strlen (cmdline));
if (curentry->append)
print (outbuf, curentry->append, grub_strlen (curentry->append));
print_string ("\n");
if (initrd || curentry->initrds)
{
@ -914,6 +985,7 @@ write_entry (struct output_buffer *outbuf,
print_string ("\n");
}
grub_free (initrd);
}
break;
case KERNEL_CHAINLOADER:
@ -949,6 +1021,7 @@ write_entry (struct output_buffer *outbuf,
break;
}
print_string (" # UNSUPPORTED localboot type ");
print_string ("\ntrue;\n");
if (print_num (outbuf, n))
return grub_errno;
print_string ("\n");
@ -1230,6 +1303,36 @@ write_entry (struct output_buffer *outbuf,
break;
}
if (grub_strcasecmp (basename, "menu.c32") == 0 ||
grub_strcasecmp (basename, "vesamenu.c32") == 0)
{
char *ptr;
char *end;
ptr = curentry->append;
if (!ptr)
return grub_errno;
while (*ptr)
{
end = ptr;
for (end = ptr; *end && !grub_isspace (*end); end++);
if (*end)
*end++ = '\0';
/* "~" is supposed to be current file, so let's skip it */
if (grub_strcmp (ptr, "~") != 0)
{
err = print_config (outbuf, menu, ptr, "");
if (err != GRUB_ERR_NONE)
break;
}
for (ptr = end; *ptr && grub_isspace (*ptr); ptr++);
}
err = GRUB_ERR_NONE;
break;
}
/* FIXME: gdb, GFXBoot, Hdt, Ifcpu, Ifplop, Kbdmap,
FIXME: Linux, Lua, Meminfo, rosh, Sanbboot */
@ -1242,70 +1345,13 @@ write_entry (struct output_buffer *outbuf,
}
case KERNEL_CONFIG:
{
char *new_cwd, *new_target_cwd;
const char *ap;
ap = curentry->append;
if (!ap)
ap = curentry->argument;
if (!ap)
ap = "";
new_cwd = get_read_filename (menu, ap);
if (!new_cwd)
return grub_errno;
new_target_cwd = get_target_filename (menu, ap);
if (!new_target_cwd)
return grub_errno;
struct syslinux_menu *menuptr;
char *newname;
int depth = 0;
newname = get_read_filename (menu, curentry->kernel_file);
if (!newname)
return grub_errno;
simplify_filename (newname);
print_string ("#");
print_file (outbuf, menu, curentry->kernel_file, NULL);
print_string (" ");
print (outbuf, newname, grub_strlen (newname));
print_string (":\n");
for (menuptr = menu; menuptr; menuptr = menuptr->parent, depth++)
if (grub_strcmp (menuptr->filename, newname) == 0
|| depth > 20)
break;
if (menuptr)
{
print_string (" syslinux_configfile -r ");
print_file (outbuf, menu, "/", NULL);
print_string (" -c ");
print_file (outbuf, menu, ap, NULL);
print_string (" ");
print_file (outbuf, menu, curentry->kernel_file, NULL);
print_string ("\n");
}
else
{
err = config_file (outbuf, menu->root_read_directory,
menu->root_target_directory, new_cwd, new_target_cwd,
newname, menu, menu->flavour);
if (err == GRUB_ERR_FILE_NOT_FOUND
|| err == GRUB_ERR_BAD_FILENAME)
{
grub_errno = err = GRUB_ERR_NONE;
print_string ("# File ");
err = print (outbuf, newname, grub_strlen (newname));
if (err)
return err;
print_string (" not found\n");
}
if (err)
return err;
}
grub_free (newname);
grub_free (new_cwd);
grub_free (new_target_cwd);
print_config (outbuf, menu, curentry->kernel_file, ap);
}
break;
case KERNEL_NO_KERNEL:
@ -1351,7 +1397,6 @@ free_menu (struct syslinux_menu *menu)
for (say = menu->say; say ; say = nsay)
{
nsay = say->next;
grub_free (say->msg);
grub_free (say);
}
@ -1421,6 +1466,13 @@ config_file (struct output_buffer *outbuf,
print_string ("\n");
}
if (menu.comments)
{
err = print (outbuf, menu.comments, grub_strlen (menu.comments));
if (err)
return err;
}
if (menu.timeout == 0 && menu.entries && menu.def)
{
err = print_entry (outbuf, &menu, menu.def);
@ -1437,12 +1489,6 @@ config_file (struct output_buffer *outbuf,
if (err)
return err;
print_string ("\n");
if (menu.comments)
{
err = print (outbuf, menu.comments, grub_strlen (menu.comments));
if (err)
return err;
}
if (menu.def)
{