All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: Al Viro <viro@ZenIV.linux.org.uk>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	sparse mailing list <linux-sparse@vger.kernel.org>
Subject: Re: [mm 4.15-rc8] Random oopses under memory pressure.
Date: Sat, 20 Jan 2018 15:45:22 +0100	[thread overview]
Message-ID: <20180120144521.xdmrnvmijeszimt2@ltop.local> (raw)
In-Reply-To: <20180120093808.7mol6d7jkngy22ky@ltop.local>

From 1f66592dd83d30ef745b1ff2b620c7935d9bc25a Mon Sep 17 00:00:00 2001
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Date: Sat, 20 Jan 2018 12:11:14 +0100
Subject: [RFC PATCH] fix: do not ignore struct/union/enum type attributes

GCC's syntax for type attributes is specified as:
    An attribute specifier list may appear as part of a struct,
    union or enum specifier. It may go either immediately after
    the struct, union or enum keyword, or after the closing brace.
    The former syntax is preferred. Where attribute specifiers
    follow the closing brace, they are considered to relate to
    the structure, union or enumerated type defined, not to any
    enclosing declaration the type specifier appears in, and the type
    defined is not complete until after the attribute specifiers.
In the section about type attributes, it's also said:
    You may specify type attributes in an enum, struct or union type
    declaration or definition by placing them immediately after the
    struct, union or enum keyword. A less preferred syntax is to
    place them just past the closing curly brace of the definition.

So, while placing the attribute after the closing curly is not
preferred, it is cleary legal (and it seems to be much more popular
than placing them just after the struct, union or enum keyword).

However, currently sparse doesn't handle this correctly:
- these attributes are parsed in declaration_specifiers() and
  added to the current decl_state
- when the ';' ending the type declaration is reached, the plain
  struct/union/enum is used and the content of the decl_state is
  simply ignored.

Fix this by calling handle_attribute() once we have reached the
closing '}' of a struct/union/enum definition and applying these
attributes, if any, directly to the current base type.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---

With this patch, a few more warnings are reported when used on thes
kernel:
- a few more abuse of __user & friends (for example how
  struct __user_cap_data_struct is used in kernel:capability.c:197)
- more annoyingly, a bunch of "invalid access past the end of ..."
  due to __packed not being ignored anymore and linearization not
  being smart enough to handle bitfields in a packed struct.

This patch is also available in the Git repository at:
  git://github.com/lucvoo/sparse-dev.git fix-ignored-attributes-v0

 parse.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/parse.c b/parse.c
index e255345fd..9df4ad359 100644
--- a/parse.c
+++ b/parse.c
@@ -627,6 +627,8 @@ struct statement *alloc_statement(struct position pos, int type)
 
 static struct token *struct_declaration_list(struct token *token, struct symbol_list **list);
 
+static void apply_ctype(struct position pos, struct ctype *thistype, struct ctype *ctype);
+
 static void apply_modifiers(struct position pos, struct decl_state *ctx)
 {
 	struct symbol *ctype;
@@ -693,6 +695,8 @@ static struct token *struct_union_enum_specifier(enum type type,
 		repos = &token->pos;
 		token = token->next;
 		if (match_op(token, '{')) {
+			struct decl_state attr = { .ctype.base_type = sym, };
+
 			// The following test is actually wrong for empty
 			// structs, but (1) they are not C99, (2) gcc does
 			// the same thing, and (3) it's easier.
@@ -702,6 +706,9 @@ static struct token *struct_union_enum_specifier(enum type type,
 			token = parse(token->next, sym);
 			token = expect(token, '}', "at end of struct-union-enum-specifier");
 
+			token = handle_attributes(token, &attr, KW_ATTRIBUTE);
+			apply_ctype(token->pos, &attr.ctype, &sym->ctype);
+
 			// Mark the structure as needing re-examination
 			sym->examined = 0;
 			sym->endpos = token->pos;
@@ -962,8 +969,6 @@ static struct token *enum_specifier(struct token *token, struct decl_state *ctx)
 	return ret;
 }
 
-static void apply_ctype(struct position pos, struct ctype *thistype, struct ctype *ctype);

  reply	other threads:[~2018-01-20 14:45 UTC|newest]

Thread overview: 108+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-05 14:45 [x86? mm? fs? 4.15-rc6] Random oopses by simple write under memory pressure Tetsuo Handa
2018-01-09 10:39 ` [mm? 4.15-rc7] " Tetsuo Handa
2018-01-10 11:49   ` [mm? 4.15-rc7] Random oopses " Tetsuo Handa
2018-01-10 12:45     ` Michal Hocko
2018-01-10 13:37       ` Tetsuo Handa
2018-01-11 13:57         ` Michal Hocko
2018-01-11 14:11           ` Tetsuo Handa
2018-01-11 14:21             ` Michal Hocko
2018-01-11 14:37               ` Tetsuo Handa
2018-01-12  1:31               ` [mm " Tetsuo Handa
2018-01-12  1:42                 ` Linus Torvalds
2018-01-12 11:22                   ` Tetsuo Handa
2018-01-14 11:54                     ` Tetsuo Handa
2018-01-14 11:54                       ` Tetsuo Handa
2018-01-15 23:05                       ` Linus Torvalds
2018-01-15 23:05                         ` Linus Torvalds
2018-01-16  1:15                         ` [mm 4.15-rc8] " Tetsuo Handa
2018-01-16  1:15                           ` Tetsuo Handa
2018-01-16  2:14                           ` Linus Torvalds
2018-01-16  2:14                             ` Linus Torvalds
2018-01-16  8:06                             ` Dave Hansen
2018-01-16  8:06                               ` Dave Hansen
2018-01-16  8:37                               ` Ingo Molnar
2018-01-16  8:37                                 ` Ingo Molnar
2018-01-16 19:30                               ` Linus Torvalds
2018-01-16 19:30                                 ` Linus Torvalds
2018-01-16 17:33                             ` Tetsuo Handa
2018-01-16 17:33                               ` Tetsuo Handa
2018-01-16 19:34                               ` Linus Torvalds
2018-01-16 19:34                                 ` Linus Torvalds
2018-01-17 11:08                                 ` Tetsuo Handa
2018-01-17 11:08                                   ` Tetsuo Handa
2018-01-17 21:39                                   ` Linus Torvalds
2018-01-17 21:39                                     ` Linus Torvalds
2018-01-17 21:51                                     ` Linus Torvalds
2018-01-17 21:51                                       ` Linus Torvalds
2018-01-17 22:04                                       ` Dave Hansen
2018-01-17 22:04                                         ` Dave Hansen
2018-01-17 22:00                                     ` Dave Hansen
2018-01-17 22:00                                       ` Dave Hansen
2018-01-17 22:15                                       ` Linus Torvalds
2018-01-17 22:15                                         ` Linus Torvalds
2018-01-18  8:12                                   ` Tetsuo Handa
2018-01-18  8:12                                     ` Tetsuo Handa
2018-01-18 12:25                                     ` Kirill A. Shutemov
2018-01-18 12:25                                       ` Kirill A. Shutemov
2018-01-18 13:12                                       ` Kirill A. Shutemov
2018-01-18 13:12                                         ` Kirill A. Shutemov
2018-01-18 14:34                                         ` Kirill A. Shutemov
2018-01-18 14:34                                           ` Kirill A. Shutemov
2018-01-18 14:38                                         ` Dave Hansen
2018-01-18 14:38                                           ` Dave Hansen
2018-01-18 14:45                                           ` Kirill A. Shutemov
2018-01-18 14:45                                             ` Kirill A. Shutemov
2018-01-18 14:51                                             ` Dave Hansen
2018-01-18 14:51                                               ` Dave Hansen
2018-01-18 16:58                                           ` Linus Torvalds
2018-01-18 16:58                                             ` Linus Torvalds
2018-01-18 14:45                                       ` Dave Hansen
2018-01-18 14:45                                         ` Dave Hansen
2018-01-18 14:58                                         ` Andrea Arcangeli
2018-01-18 14:58                                           ` Andrea Arcangeli
2018-01-18 16:56                                           ` Kirill A. Shutemov
2018-01-18 16:56                                             ` Kirill A. Shutemov
2018-01-18 17:26                                             ` Luck, Tony
2018-01-18 17:26                                               ` Luck, Tony
2018-01-18 17:28                                               ` Linus Torvalds
2018-01-18 17:28                                                 ` Linus Torvalds
2018-01-18 17:26                                             ` Linus Torvalds
2018-01-18 17:26                                               ` Linus Torvalds
2018-01-18 23:49                                               ` Kirill A. Shutemov
2018-01-18 23:49                                                 ` Kirill A. Shutemov
2018-01-19 12:55                                                 ` Matthew Wilcox
2018-01-19 12:55                                                   ` Matthew Wilcox
2018-01-19 18:42                                                   ` Linus Torvalds
2018-01-19 18:42                                                     ` Linus Torvalds
2018-01-19 22:12                                                     ` Al Viro
2018-01-19 22:12                                                       ` Al Viro
2018-01-19 22:53                                                       ` Linus Torvalds
2018-01-19 22:53                                                         ` Linus Torvalds
2018-01-20  2:02                                                         ` Al Viro
2018-01-20  2:02                                                           ` Al Viro
2018-01-20  5:24                                                           ` Al Viro
2018-01-20  5:24                                                             ` Al Viro
2018-01-20  9:38                                                             ` Luc Van Oostenryck
2018-01-20  9:38                                                               ` Luc Van Oostenryck
2018-01-20  9:38                                                               ` Luc Van Oostenryck
2018-01-20 14:45                                                               ` Luc Van Oostenryck [this message]
2018-01-22 13:26                                                     ` Rasmus Villemoes
2018-01-22 19:58                                                       ` Linus Torvalds
2018-01-18 15:40                                         ` Kirill A. Shutemov
2018-01-18 15:40                                           ` Kirill A. Shutemov
2018-01-18 17:22                                           ` Michal Hocko
2018-01-18 17:22                                             ` Michal Hocko
2018-01-19 10:02                                             ` Kirill A. Shutemov
2018-01-19 10:02                                               ` Kirill A. Shutemov
2018-01-19 10:33                                               ` Michal Hocko
2018-01-19 10:33                                                 ` Michal Hocko
2018-01-19 11:49                                                 ` Kirill A. Shutemov
2018-01-19 11:49                                                   ` Kirill A. Shutemov
2018-01-19 12:07                                                   ` Michal Hocko
2018-01-19 12:07                                                     ` Michal Hocko
2018-01-19 12:30                                                     ` Kirill A. Shutemov
2018-01-19 12:30                                                       ` Kirill A. Shutemov
2018-01-19  2:01                                           ` Tetsuo Handa
2018-01-19  2:01                                             ` Tetsuo Handa
2018-01-11 18:11             ` [mm? 4.15-rc7] " Linus Torvalds
2018-01-11 20:59               ` Tetsuo Handa

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=20180120144521.xdmrnvmijeszimt2@ltop.local \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=torvalds@linux-foundation.org \
    --cc=viro@ZenIV.linux.org.uk \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.