From patchwork Fri Jul 13 08:56:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Peter Nilsson X-Patchwork-Id: 170830 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id AC6262C0356 for ; Fri, 13 Jul 2012 18:57:18 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1342774640; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Received:Received:Date:Message-Id:From:To:CC: In-reply-to:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Mailing-List:Precedence:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=+y8tq2UVcGC28H+CSp01ClFBiHU=; b=pycTkpc9Gnklio7 yXcwTXqmrh3UX0Ysuw/4i2hBBLPGjRGVbP1kEwkplDSDPW3lwMoq1qNK1jgHC7JZ wA3jAiKlKfjmk3P+4SncJuDSkTn8+Cck+3qoS5fvYwPhYa9YiIT10cHFONhuesYm MafdlHcMPS04Z7UROiJPCdKLqLas= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Received:Received:Received:Received:Date:Message-Id:From:To:CC:In-reply-to:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=JMTivTz5PADG3BqEX4qs47GbKyWGDXSq5RFJ/PzDYjIoVme56l6oJdGTZ4yeZn ycnclddYChyru/rtWbH7qRKrn3Z91Mub7uBCs4n5vPUV9mukhCowoi/+fVrEDgpr QZ0X7e9z53JQlqX9JADDZodaIDs0mf7q19zYnVTRmYzPY=; Received: (qmail 17724 invoked by alias); 13 Jul 2012 08:57:15 -0000 Received: (qmail 17712 invoked by uid 22791); 13 Jul 2012 08:57:14 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from ra.se.axis.com (HELO ra.se.axis.com) (195.60.68.13) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 13 Jul 2012 08:56:57 +0000 Received: from localhost (localhost [127.0.0.1]) by ra.se.axis.com (Postfix) with ESMTP id 2920513ACE; Fri, 13 Jul 2012 10:56:56 +0200 (CEST) Received: from ra.se.axis.com ([127.0.0.1]) by localhost (ra.se.axis.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Q-zzSeO0Tkb4; Fri, 13 Jul 2012 10:56:54 +0200 (CEST) Received: from seth.se.axis.com (seth.se.axis.com [10.0.2.172]) by ra.se.axis.com (Postfix) with ESMTP id E47E313A1D; Fri, 13 Jul 2012 10:56:53 +0200 (CEST) Received: from ignucius.se.axis.com (ignucius.se.axis.com [10.88.21.50]) by seth.se.axis.com (Postfix) with ESMTP id AC5273E0B8; Fri, 13 Jul 2012 10:56:53 +0200 (CEST) Received: from ignucius.se.axis.com (localhost [127.0.0.1]) by ignucius.se.axis.com (8.12.8p1/8.12.8/Debian-2woody1) with ESMTP id q6D8ur75019680; Fri, 13 Jul 2012 10:56:53 +0200 Received: (from hp@localhost) by ignucius.se.axis.com (8.12.8p1/8.12.8/Debian-2woody1) id q6D8uqMM019676; Fri, 13 Jul 2012 10:56:52 +0200 Date: Fri, 13 Jul 2012 10:56:52 +0200 Message-Id: <201207130856.q6D8uqMM019676@ignucius.se.axis.com> From: Hans-Peter Nilsson To: gcc-patches@gcc.gnu.org CC: stevenb.gcc@gmail.com, rsandifo@nildram.co.uk, bernds@codesourcery.com In-reply-to: (message from Richard Guenther on Fri, 13 Jul 2012 10:08:05 +0200) Subject: Re: Fix PR53908 MIME-Version: 1.0 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org > From: Richard Guenther > Date: Fri, 13 Jul 2012 10:08:05 +0200 > On Fri, Jul 13, 2012 at 9:59 AM, Hans-Peter Nilsson > wrote: > > Ok for 4.7 too? > > Of course. Committed to trunk as follows, including the test-case which doesn't fail on trunk but does on 4.6 and 4.7. Will commit to 4.7 branch too. I'll leave 4.6 to those interested enough to invest time to do the testing. gcc: 2012-07-13 Richard Sandiford Steven Bosscher Bernd Schmidt PR rtl-optimization/53908 * df-problems.c (can_move_insns_across): When doing memory-reference book-keeping, handle call insns. gcc/testsuite: 2012-07-13 Hans-Peter Nilsson PR rtl-optimization/53908 * gcc.dg/torture/pr53908.c: New test. brgds, H-P Index: gcc/df-problems.c =================================================================== --- gcc/df-problems.c (revision 189440) +++ gcc/df-problems.c (working copy) @@ -4068,6 +4068,19 @@ can_move_insns_across (rtx from, rtx to, for (insn = across_to; ; insn = next) { + if (CALL_P (insn)) + { + if (RTL_CONST_OR_PURE_CALL_P (insn)) + /* Pure functions can read from memory. Const functions can + read from arguments that the ABI has forced onto the stack. + Neither sort of read can be volatile. */ + memrefs_in_across |= MEMREF_NORMAL; + else + { + memrefs_in_across |= MEMREF_VOLATILE; + mem_sets_in_across |= MEMREF_VOLATILE; + } + } if (NONDEBUG_INSN_P (insn)) { memrefs_in_across |= for_each_rtx (&PATTERN (insn), find_memory, --- /dev/null Tue Oct 29 15:57:07 2002 +++ gcc/testsuite/gcc.dg/torture/pr53908.c Thu Jul 12 19:22:59 2012 @@ -0,0 +1,288 @@ +/* { dg-do run } */ +/* SEGV at comment below. */ +typedef unsigned int size_t; +typedef enum har { + he_fatal = (-199), + he_not_initialized, + he_bad_input, + he_memory_too_small, + he_bad_action, + he_duplicate, + he_bad_nonce, + he_stale_nonce, + he_bad_credentials, + he_bad_user, + he_no_such_user, + he_bad_passwd, + he_unknown_auth_scheme, + he_not_found, + he_failed_digest_file_check, + he_failed_digest_file_save, + he_process_not_privileged, + he_other, + he_end_of_range, + ha_no_error = 0, + ha_no_value = 1 +} har; +typedef enum realm_type +{ + axis_realm = 0, + ws_realm +} realm_type; + +__attribute__((__noclone__, __noinline__)) +har has_www_auth(char *, size_t, realm_type, har); + +__attribute__((__noclone__, __noinline__)) +har has_auth_user(const char *, const char *, realm_type, char *, size_t); + +__attribute__((__noclone__, __noinline__)) +char *ha_get_string_value(void); + +typedef struct +{ + unsigned int track_id; + char* user; + char* realm; + char* authent; + int internal_realm; +} request; +enum user_response { + file_not_found_user_response = -3, + access_denied_user_response = -2, + no_user_response = -1, + ok_user_response = 0 +}; +struct realm_group { + char *name; + int id; + struct realm_group *next; +}; +struct realm { + char *name; + char *space; + struct realm_group *groups; + struct realm *next; +}; +struct user_info { + char *name; + int no_groups; + int groups[128]; + struct user_info *next; +}; +static struct user_info *find_user(const char *user_name); +static int is_member_of_groups(const struct user_info *user_item, + const struct realm_group *groups); +int authent_author(request *req); +struct realm *realms = ((void *)0); +struct user_info *users = ((void *)0); +static struct user_info* +find_user(const char *user_name) +{ + struct user_info *user_item; + user_item = users; + while (user_item != ((void *)0)) { + /* SEGV due to NULL access here on user_name. See also comment below. */ + if ((__builtin_strcmp(user_item->name, user_name) == 0)) + break; + user_item = user_item->next; + } + return user_item; +} +static int +is_member_of_groups(const struct user_info *user_item, + const struct realm_group *groups) +{ + const struct realm_group *group_item; + int i; + group_item = groups; + while (group_item != ((void *)0)) { + for (i = 0; i < user_item->no_groups; i++) + if (user_item->groups[i] == group_item->id) + return 0; + group_item = group_item->next; + } + return -1; +} +char *foo (void) __attribute__((__noclone__, __noinline__)); +char* g_strdup (const char *str) __attribute__((__malloc__, __noclone__, __noinline__)); +int g_strcmp0 (const char *str1, const char *str2); +static int +is_basic(char **user) +{ + char *passwd_ptr; + char *authent = foo(); + passwd_ptr = __builtin_strchr(authent, ':'); + if (passwd_ptr != ((void *)0)) { + *user = g_strdup(authent); + return 0; + } + return -1; +} +static int +is_digest(char **user) +{ + int ret_val = -1; + char *authent; + authent = ha_get_string_value(); + if (authent) { + *user = g_strdup(authent); + ret_val = 0; + } + return ret_val; +} +__attribute__((__noclone__, __noinline__)) +void g_free (void * mem); +static enum user_response +get_user_info_from_header(const realm_type type, + char **user_name, + struct user_info **user_item) +{ + int ret_val = no_user_response; + if ((type == ws_realm)) { + if (is_basic(user_name) == 0) + ret_val = access_denied_user_response; + if (is_digest(user_name) == 0) + ret_val = ok_user_response; + } else { + if (is_basic(user_name) < 0 && + /* Load of *user_name here, but not after the is_digest call. */ + is_digest(user_name) < 0) + ; + else if ((*user_item = find_user(*user_name)) != ((void *)0)) + ret_val = ok_user_response; + else + ret_val = access_denied_user_response; + if (ret_val != ok_user_response) + g_free(*user_name); + } + return ret_val; +} +static enum user_response +authenticate_user(request *req, + char **user_name, + struct user_info **user_item) +{ + char *authent = ((void *)0); + har resp = ha_no_value; + enum user_response user_resp; + int ret_val = no_user_response; + if (req->authent && __builtin_strlen(req->authent)) { + authent = req->authent; + user_resp = get_user_info_from_header(req->internal_realm, + user_name, + user_item); + if (user_resp == ok_user_response) { + resp = has_auth_user(authent, 0, req->internal_realm, "", 1); + if (resp == ha_no_error) + ret_val = ok_user_response; + else if (resp != he_stale_nonce) + ret_val = access_denied_user_response; + } else if (user_resp == access_denied_user_response) + ret_val = access_denied_user_response; + } + if (resp != he_memory_too_small && resp != ha_no_error) + resp = has_www_auth("", 1, req->internal_realm, resp); + return ret_val; +} + +int __attribute__ ((__noinline__, __noclone__)) +authent_author(request *req) +{ + struct realm *realm; + char *user_name = ((void *)0); + struct user_info *user_item = ((void *)0); + int res = 0; + asm (""); + realm = realms; + if (__builtin_strcmp("Wsd", realm->name) == 0) { + req->internal_realm = ws_realm; + is_digest(&user_name); + } + if (authenticate_user(req, &user_name, &user_item) < 0) { + if (user_name != ((void *)0)) + req->user = user_name; + res = -2; + goto authent_author_return; + } + if (is_member_of_groups(user_item, realm->groups) < 0) + res = -1; +authent_author_return: + return res; +} + +int good0, good1, good2; + +__attribute__ ((__noinline__, __noclone__)) +char *foo(void) +{ + asm (""); + good0++; + return ""; +} + +__attribute__ ((__noinline__, __noclone__)) +char *ha_get_string_value(void) +{ + asm (""); + good1++; + return "f"; +} + +__attribute__ ((__noinline__, __noclone__)) +har has_auth_user(const char *a, const char *b, realm_type c, char *d, size_t e) +{ + asm (""); + if (*a != 'z' || a[1] != 0 || b != 0 || c != axis_realm || *d != 0 + || e != 1) + __builtin_abort (); + return ha_no_error; +} + +__attribute__ ((__noinline__, __noclone__)) +har has_www_auth(char *a, size_t b, realm_type c, har d) +{ + (void)(*a+b+c+d); + asm (""); + __builtin_abort (); +} + + +char *strdupped_user = "me"; +__attribute__((__malloc__, __noclone__, __noinline__)) +char* g_strdup (const char *str) +{ + asm (""); + if (*str != 'f') + __builtin_abort (); + good2++; + return strdupped_user; +} + +__attribute__((__noclone__, __noinline__)) +void g_free (void * mem) +{ + (void)mem; + asm (""); + __builtin_abort (); +} + +struct user_info me = { .name = "me", .no_groups = 1, .groups = {42}, .next = 0}; +struct user_info you = { .name = "you", .next = &me}; +struct realm_group xgroups = { .name = "*", .id = 42, .next = 0}; + +int main(void) +{ + char *orig_user = "?"; + struct realm r = { .name = "x", .space = "space?", .groups = &xgroups, .next = 0}; + request req = { .user = orig_user, .realm = "!", .authent = "z", + .internal_realm = axis_realm}; + realms = &r; + users = &you; + if (authent_author (&req) != 0 || good0 != 1 || good1 != 1 || good2 != 1 + || req.user != orig_user + || req.internal_realm != axis_realm) + __builtin_abort (); + __builtin_exit (0); +} +