read --echo=[yes|no|wildcard]
PATCH 1/1 read --echo=[yes|no|wildcard]
Adds a parameter to define echoing behaviour in read. Then one can use --echo=no or --echo=wildcard to make it suitable for reading passwords.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)
2008-02-10 Robert Millan <[email protected]>
* commands/read.c (options): New struct.
(grub_getline): Receive a hook as argument, that will be invoked for each character read instead of directly printing it. This lets the caller choose which action is appropiate.
Echo the final newline.
(grub_cmd_read): Parse --echo parameter to determine echoing behaviour. Pass a hook to grub_getline() that implements behaviour determined by --echo.
(grub_read_init): Pass `options' parameter to grub_register_command().
commands/read.c renamed from grub2/commands/read.c +50 -6
@@ -24,8 +24,14 @@#include <grub/term.h> #include <grub/types.h> +static const struct grub_arg_option options[] = + { + {"echo" ,'e' ,0 ,"whether to echo user input" ,"[yes|no|wildcard]" ,ARG_TYPE_STRING }, + {0 ,0 ,0 ,0 ,0 ,0 } + }; +static char * -grub_getline (void ) +grub_getline (void (*hook) (char c)) {int i;char *line;
@@ -39,8 +45,7 @@ grub_getline (void)while ((line[i -1 ] !='\n' ) && (line[i -1 ] !='\r' )) { line[i] =grub_getkey (); -if (grub_isprint (line[i])) -grub_putchar (line[i]); +hook (line[i]); i++; tmp =grub_realloc (line,1 + i +sizeof ('\0' ));if (! tmp)
@@ -51,14 +56,53 @@ grub_getline (void) line = tmp; } line[i] ='\0' ; +grub_putchar ('\n' );return line; } +enum +{ +ECHO_YES , +ECHO_NO , +ECHO_WILDCARD , +}; +static grub_err_t -grub_cmd_read (struct grub_arg_list *state UNUSED, int argc, char **args) +grub_cmd_read (struct grub_arg_list *state,int argc,char **args) { -char *line =grub_getline (); +char *line; +int echo =ECHO_YES ; + +if (state[0 ].set) + { +grub_printf ("%s\n" , state[0 ].arg); +if (!grub_strcmp (state[0 ].arg,"no" )) + echo =ECHO_NO ; +else if (!grub_strcmp (state[0 ].arg,"wildcard" )) + echo =ECHO_WILDCARD ; +else if (grub_strcmp (state[0 ].arg,"yes" )) +return grub_error (GRUB_ERR_BAD_ARGUMENT ,"invalid argument" ); + } + + autovoid hook (char ); +void hook (char c) + { +if (!grub_isprint (c)) +return ; + +switch (echo) + { +case ECHO_YES : +grub_putchar (c); +break ; +case ECHO_WILDCARD : +grub_putchar ('*' ); +break ; + } + } + + line =grub_getline (hook);if (! line)return grub_errno;if (argc >0 )
@@ -72,7 +116,7 @@ grub_cmd_read (struct grub_arg_list *staGRUB_MOD_INIT (read) {grub_register_command ("read" , grub_cmd_read,GRUB_COMMAND_FLAG_CMDLINE , -"read [ENVVAR]" ,"Set variable with user input" ,0 ); +"read [ENVVAR]" ,"Set variable with user input" , options); }GRUB_MOD_FINI (read)
Quoted 2 lines · Robert Millan
Adds a parameter to define echoing behaviour in read. Then one can use --echo=no or --echo=wildcard to make it suitable for reading passwords.
I wonder how suitable it is for passwords -- is the memory always erased before jumping to e.g. Linux? (and is it important to hide it from the prying eyes of the root system? Probably...)
Quoted 7 lines · Isaac Dupree
Quoted 2 lines · Robert Millan
Adds a parameter to define echoing behaviour in read. Then one can use --echo=no or --echo=wildcard to make it suitable for reading passwords.
I wonder how suitable it is for passwords -- is the memory always erased before jumping to e.g. Linux? (and is it important to hide it from the prying eyes of the root system? Probably...)
Why? This suggests that the Linux image you just booted is not trusted, which I find a bit strange.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)
Quoted 8 lines · Robert Millan
Quoted 4 lines · Isaac Dupree
Quoted 2 lines · Robert Millan
Adds a parameter to define echoing behaviour in read. Then one can use --echo=no or --echo=wildcard to make it suitable for reading passwords.
I wonder how suitable it is for passwords -- is the memory always erased before jumping to e.g. Linux? (and is it important to hide it from the prying eyes of the root system? Probably...)
Why? This suggests that the Linux image you just booted is not trusted, which I find a bit strange.
well, suppose it runs for a few months, doesn't happen to overwrite that memory, and then someone hacks in and gets root access (unpatched security flaws can happen) and then reads the raw memory. Then the local boot **and the password itself** might be unknowingly compromised (rather than just probably a hash of the password). (plus you might be booting Windows ^_^, or anything really.) It's generally good practice, I think... that GnuPG tries to do, for example? (I could be remembering wrong)
-Isaac
Quoted 13 lines · Isaac Dupree
Quoted 11 lines · Robert Millan
Quoted 6 lines · Isaac Dupree
Quoted 2 lines · Robert Millan
Adds a parameter to define echoing behaviour in read. Then one can use --echo=no or --echo=wildcard to make it suitable for reading passwords.
I wonder how suitable it is for passwords -- is the memory always erased before jumping to e.g. Linux? (and is it important to hide it from the prying eyes of the root system? Probably...)
Why? This suggests that the Linux image you just booted is not trusted, which
I find a bit strange.
Quoted 8 lines
well, suppose it runs for a few months, doesn't happen to overwrite that memory, and then someone hacks in and gets root access (unpatched security flaws can happen) and then reads the raw memory. Then the local boot **and the password itself** might be unknowingly compromised (rather than just probably a hash of the password). (plus you might be booting Windows ^_^, or anything really.) It's generally good practice, I think... that GnuPG tries to do, for example? (I could be remembering wrong)
I think that it'd be better to just erase all our environment in grub_machine_fini() or a similar routine, than to give read specific knowledge that its data needs this kind of special protection. Besides, it wouldn't be that simple since the data is controlled by the user via grub.cfg, not directly by GRUB.
Anyway, untill we support hashing this doesn't provide any additional security, since you can get the same from grub.cfg ;-)
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)
Quoted 5 lines · Robert Millan
I think that it'd be better to just erase all our environment in
grub_machine_fini()or a similar routine, than to give read specific knowledge that its data needs this kind of special protection. Besides, it wouldn't be that simple since the data is controlled by the user via grub.cfg, not directly by GRUB.
I wonder if this erasing would take any significant amount of time (in which case there would be a reason not to implement that to happen all the time)
Quoted 2 lines
Anyway, untill we support hashing this doesn't provide any additional security, since you can get the same from grub.cfg ;-)
fairly true, assuming nothing weird happens like grub.cfg being thoroughly deleted in the meantime :-)
anyway if a hash is used that takes (by design) around one second on the machine (e.g. sha256 repeated thousands? millions? of times), then I suppose the time taken to erase the memory used by GRUB would be trivial in comparison, assuming(rightly or wrongly) a good implementation...
-Isaac
Quoted 4 lines · Isaac Dupree
anyway if a hash is used that takes (by design) around one second on the machine (e.g. sha256 repeated thousands? millions? of times), then I suppose the time taken to erase the memory used by GRUB would be trivial in comparison, assuming(rightly or wrongly) a good implementation...
The problem is not time, it's just to find the right way to do it.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)
Quoted 4 lines · Robert Millan
Quoted 1 line · Isaac Dupree
anyway if a hash is used that takes (by design) around one second on the machine (e.g. sha256 repeated thousands? millions? of times), then I suppose the time taken to erase the memory used by GRUB would be trivial in comparison, assuming(rightly or wrongly) a good implementation...
The problem is not time, it's just to find the right way to do it.
yeah. probably involves thinking about GRUB's allocation and deallocation mechanisms, which I don't know anything about and don't have time to investigate :-/
-Isaac
Quoted 2 lines · Robert Millan
Adds a parameter to define echoing behaviour in read. Then one can use --echo=no or --echo=wildcard to make it suitable for reading passwords.
Can you describe how you are planning to use it?
Okuji
PATCH 1/1 erase variable data on user unset
In reply to Isaac DupreeQuoted 7 lines · Isaac Dupree
Quoted 6 lines · Robert Millan
Quoted 4 lines · Isaac Dupree
anyway if a hash is used that takes (by design) around one second on the machine (e.g. sha256 repeated thousands? millions? of times), then I suppose the time taken to erase the memory used by GRUB would be trivial in comparison, assuming(rightly or wrongly) a good implementation...
Quoted 5 lines
Quoted 1 line
The problem is not time, it's just to find the right way to do it.
yeah. probably involves thinking about GRUB's allocation and deallocation mechanisms, which I don't know anything about and don't have time to investigate :-/
This should address your concern. As to why I propose to put this in unset command rather than kernel, since GRUB itself doesn't have any mechanisms where a variable would contain sensible information, I think it's better to protect user variables only.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)
2008-02-10 Robert Millan <[email protected]>
* normal/command.c (unset_command): Erase the contents of the variable we're about to unset, before actually unsetting it.
normal/command.c renamed from grub2/normal/command.c +9 -0
@@ -274,10 +274,19 @@ static grub_err_t unset_command (struct grub_arg_list *state __attribute__ ((unused)), int argc, char **args) { +char *value; +if (argc <1 )return grub_error (GRUB_ERR_BAD_ARGUMENT ,"no environment variable specified" ); + value =grub_env_get (args[0 ]); + +/* Users may store sensitive information in their variables (e.g. passwords), +so erase its content here when they choose to unset them. */ +if (value) +grub_memset (value,0 ,grub_strlen (value)); +grub_env_unset (args[0 ]);return 0 ; }
Quoted 5 lines · Yoshinori K. Okuji
Quoted 2 lines · Robert Millan
Adds a parameter to define echoing behaviour in read. Then one can use --echo=no or --echo=wildcard to make it suitable for reading passwords.
Can you describe how you are planning to use it?
This doesn't work yet, because of the lexer bug I mentioned in the other thread, but roughly:
menuentry "LOCK" {
set menu_lock=1
}
menuentry "UNLOCK" {
echo -n "Password: "
read --echo=wildcard password
if test $password=grubrocks ; then
unset menu_lock
fi
}
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)
Re: [PATCH] erase variable data on user unset
In reply to Robert MillanQuoted 5 lines · Robert Millan
This should address your concern. As to why I propose to put this in unset command rather than kernel, since GRUB itself doesn't have any mechanisms where a variable would contain sensible information, I think it's better to protect user variables only.
(for size reasons of course)
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)
Re: [PATCH] erase variable data on user unset
In reply to Robert MillanQuoted 11 lines · Robert Millan
Quoted 5 lines · Isaac Dupree
Quoted 3 lines · Robert Millan
Quoted 1 line · Isaac Dupree
anyway if a hash is used that takes (by design) around one second on the machine (e.g. sha256 repeated thousands? millions? of times), then I suppose the time taken to erase the memory used by GRUB would be trivial in comparison, assuming(rightly or wrongly) a good implementation...
The problem is not time, it's just to find the right way to do it.
yeah. probably involves thinking about GRUB's allocation and deallocation mechanisms, which I don't know anything about and don't have time to investigate :-/
This should address your concern. As to why I propose to put this in unset command rather than kernel, since GRUB itself doesn't have any mechanisms where a variable would contain sensible information, I think it's better to protect user variables only.
okay, is the idea that the script should explicitly unset sensitive variables, or are they all automatically unset upon boot? (if "unset" command is loaded?)
Anyway, thanks for looking into this!
-Isaac
Re: [PATCH] erase variable data on user unset
on second thought, if grub is going to be able to boot kernels that are on encrypted partitions, the password might go more places in grub and/or have to be retained until boot time, depending how it works...
Re: [PATCH] erase variable data on user unset
Quoted 3 lines · Isaac Dupree
on second thought, if grub is going to be able to boot kernels that are on encrypted partitions, the password might go more places in grub and/or have to be retained until boot time, depending how it works...
Not until boot time, just up to the load command. I guess you mean something like:
echo -n "Password: "
read passwordlvm_somecommand $password
linux (lvm-device)/boot/linux.img
unset password
boot
Here, the lvm module would be responsible for its own copy of the password. It does already know that sensitive information is being handled, so when grub_lvm_fini() is called, it'll erase it.
The other copy is in the environment, so user clears it after loading linux, because our env handler doesn't know that some variables might contain sensitive info.
Signature · 5 lines
Robert Millan <GPLv2> I know my rights; I want my phone call! <DRM> What use is a phone call… if you are unable to speak? (as seen on /.)