mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Solar Designer <solar@openwall.com>
To: musl@lists.openwall.com
Subject: Re: cluts review
Date: Thu, 14 Jul 2011 01:44:59 +0400	[thread overview]
Message-ID: <20110713214459.GA26971@openwall.com> (raw)
In-Reply-To: <20110713203945.GA26271@openwall.com>

On Thu, Jul 14, 2011 at 12:39:45AM +0400, Solar Designer wrote:
> Rich might be able to provide a better / more correct answer (I'd be
> interested), but here's my understanding:
> 
> The clobbering happens when those variables are kept in registers rather
> than in memory (on stack).  To prevent it from happening, you may force
> the compiler not to place the variables in registers.  One way to do it
> is to take the variable's address:
> 
> (void) &var;
> 
> (I am not sure what guarantees this provides.  IIRC, it was documented
> to provide the needed safety under GNU C.)

I can't find where I think I previously saw this documented for gcc.

> Another is to declare it "volatile", but this does a bit more than is
> needed (so has extra performance impact).

This is documented in lots of places.  For example:

https://www.securecoding.cert.org/confluence/display/seccode/MSC22-C.+Use+the+setjmp(),+longjmp()+facility+securely

and indeed we're taking a risk by potentially interrupting and
re-entering non-async-signal safe functions:

https://www.securecoding.cert.org/confluence/display/seccode/SIG32-C.+Do+not+call+longjmp%28%29+from+inside+a+signal+handler

IIRC, I brought this up before, and Rich correctly pointed out that we
were doing it for low-risk functions only, and this is only a test suite.

> Better yet, structure your function such that there are no variables to
> clobber.  If you put your sigsetjmp() at the very beginning of the
> function, before any local variable is assigned a value, there's nothing
> to clobber yet.

Here's an example:

http://cvsweb.openwall.com/cgi/cvsweb.cgi/Owl/packages/popa3d/popa3d/protocol.c?rev=HEAD

int pop_handle_state(struct pop_command *commands)
{
	char line[POP_BUFFER_SIZE];
	char *params;
	struct pop_command *command;
	int response;

	if (sigsetjmp(pop_timed_out, 1)) return POP_CRASH_NETTIME;

	while (pop_get_line(line, sizeof(line))) {
...

It also invokes siglongjmp() from a signal handler, but it only installs
the handler for the duration of a read() syscall, which is async signal
safe, so there's no risk.

Alexander


  reply	other threads:[~2011-07-13 21:44 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-13 11:07 Solar Designer
2011-07-13 12:02 ` Luka Marčetić
2011-07-13 12:21   ` Solar Designer
2011-07-13 12:57     ` Luka Marčetić
2011-07-13 13:42       ` Rich Felker
2011-07-13 14:21         ` Solar Designer
2011-07-13 13:54       ` Solar Designer
2011-07-13 14:00         ` Rich Felker
2011-07-13 14:31           ` Solar Designer
2011-07-13 14:03     ` Rich Felker
2011-07-13 14:37       ` Solar Designer
2011-07-13 16:03   ` Solar Designer
2011-07-13 16:55     ` Luka Marčetić
2011-07-13 17:05       ` Solar Designer
2011-07-13 17:25         ` Luka Marčetić
2011-07-13 17:52           ` Solar Designer
2011-07-13 19:29             ` Luka Marčetić
2011-07-13 19:55               ` Rich Felker
2011-07-13 20:39               ` Solar Designer
2011-07-13 21:44                 ` Solar Designer [this message]
2011-07-13 19:52             ` Rich Felker
2011-07-13 20:03       ` Rich Felker
2011-07-14 18:56       ` Rich Felker
2011-07-13 13:38 ` Rich Felker
2011-07-13 14:12   ` Solar Designer
2011-07-13 14:26     ` Rich Felker
2011-07-13 14:46       ` Solar Designer
2011-07-13 16:25   ` Luka Marčetić
2011-07-13 17:03     ` Solar Designer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110713214459.GA26971@openwall.com \
    --to=solar@openwall.com \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).