All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: George Dunlap <dunlapg@umich.edu>
Cc: Juergen Gross <jgross@suse.com>,
	Stefano Stabellini <stefanos@xilinx.com>,
	Stefano Stabellini <sstabellini@kernel.org>,
	Wei Liu <wei.liu2@citrix.com>,
	Andrew Cooper <andrew.cooper3@citrix.com>,
	Julien Grall <julien.grall@gmail.com>,
	Julien Grall <julien.grall@arm.com>,
	Jan Beulich <JBeulich@suse.com>,
	Stewart Hildebrand <Stewart.Hildebrand@dornerworks.com>,
	xen-devel <xen-devel@lists.xenproject.org>
Subject: Re: [PATCH v6 1/4] xen: introduce SYMBOL
Date: Fri, 1 Feb 2019 12:53:44 -0800 (PST)	[thread overview]
Message-ID: <alpine.DEB.2.10.1902011239120.22962@sstabellini-ThinkPad-X260> (raw)
In-Reply-To: <CAFLBxZYdzV43SxpMiF7X=zcNnxfkJDQq5zkUnuThzE-rBuS=yA@mail.gmail.com>

On Fri, 1 Feb 2019, George Dunlap wrote:
> On Tue, Jan 22, 2019 at 9:17 AM Jan Beulich <JBeulich@suse.com> wrote:
> >
> > >>> On 22.01.19 at 00:41, <sstabellini@kernel.org> wrote:
> > > We haven't managed to reach consensus on this topic. Your view might be
> > > correct, but it is not necessarily supported by compilers' behavior,
> > > which depends on the opinion of compilers engineers on the topic, and
> > > MISRAC compliance, which depends on the opinion of MISRAC specialists on
> > > the topic. If we take your suggested approach we end up with the code
> > > most likely to break in case the compilers engineers or the MISRAC
> > > experts disagree with you. In this case, being right doesn't necessarily
> > > lead to the code less likely to break.
> > >
> > > Regardless, if that is the decision of the Xen community as a whole,
> > > I'll follow it. My preference remains with approach 3. (var.S), followed
> > > by approach 2. (SYMBOL_HIDE returns uintptr_t), but I am willing to
> > > refresh my series to do approach 1. (SYMBOL_HIDE returns pointer type)
> > > if that is the only way forward.
> > >
> > > Let us come to a conclusion so that we can move on.
> >
> > How can we come to a conclusion when things remain unclear? I see
> > only two ways forward - either we settle the dispute (which I'm
> > afraid would require involvement of someone accepted by all of us
> > as a "C language lawyer", which would include judgment about the
> > MISRA-C implications),
> 
> Well, no, I don't think a "C language lawyer" would help here.
> 
> You keep making the case for C spec compliance as though we're dealing
> with zealous but ultimately rational people, who will a) almost never
> violate the C spec, and b) actually fix their compiler if their
> language does violate the spec.
> 
> But it's clear from reading those threads that this is not the case.
> Over and over people presented  clear arguments, from the spec and the
> spec committee, showing that what gcc was doing was both wrong and
> impractical; and the compiler people kept coming up with more and more
> tortuous interpretations to justify the compiler's behavior.  The
> whole thing with supposing that the C standard anticipated a
> compacting garbage collector was the cherry on the cake.
> 
> We're not living in a rational world where if we just follow the rules
> we'll be safe.  We have a dictat from the high council in the form of
> a C spec which is divorced from actual usage and utility, and we have
> a load of insane fanatics trying to impose their interpretation
> doctrinal purity on the world, and ready to burn any heretics writing
> code that doesn't match the view they happen to hold that day.  "The
> compiler can't optimize this because it can't prove they're different
> objects" is a fine principle, but it's pretty clear that they're
> willing to continue optimizing things even if you *can* prove they
> fall inside the rules of pointer comparison.

That made me laugh very hard :-D  in a "sad but true" kind of way.


> In such a situation, *there is no perfectly safe option*.  No matter
> what position you take, the fanatics may end up deciding that you're a
> heretic and need to be burned at the stake.  Might they decide that
> they know that extern pointers point to different objects, and
> therefore can't be compared? Maybe!  Might they decide they can pierce
> the veil of asm to determine the source of unsigned longs they're
> comparing? Possibly!  Could they decide that a uintptr_t received from
> the heathen lands of assembly is anathema, and therefore casting it to
> a pointer is undefined behavior?  They certainly could!
> 
> And even if you do convince them their interpretation is wrong and
> they fix their compiler, the damage is still done: there are still,
> out in the wild, vulnerable binaries built with buggy compilers and
> buggy compilers that produce vulnerable binaries, until they all die
> of old age.
> 
> *Any* interpretation we choose may be declared at some point by the
> compiler folks to be heresy.  But, there are less safe option and more
> safe options.  Our goal with regard to the C Standard cannot,
> unfortunately, be "follow the rules".  Our goal must be to *minimize
> the risk* of being caught in the next wave of the compiler
> optimization purges.
> 
> MISRA is quirky and often impractical, but ultimately their goal with
> rules like this is to try to protect you from the fanatics who write
> compilers (insofar as that is possible).  So if we do our best to be
> as safe as possible from the compiler fanatics, we have a pretty good
> chance of being considered MISRA compliant as well.
> 
> It seems to me that anything that involves directly comparing pointers
> is simply more likely to be come the target of optimization (and thus
> more dangerous) than comparing unsigned long and uintptr_t.  And
> although I'm not terribly familiar with the "intptr" types, it seems
> to me that casting from uintptr_t is less likely to ever be considered
> deviant behavior than casting from unsigned long.
> 
> As such, I think casting the return value of asm to a pointer is far
> too dangerous.  Using extern pointers seems quite dangerous to me as
> well.  So it seems to me that using asm to generate an unsigned long
> would be absolute minimum behavior.  Using uintprt_t values, and in
> particular importing them from assembly, might give us yet another
> level of safety (in case unsigned long -> pointer casts ever become a
> target).
> 
> Are these guaranteed to avoid "UB hazard" issues in the future?  Of
> course not; nothing can.  But they seem to me to be a lot less risky
> than asm -> ptr or extern pointers.

This is a great well-written writeup George. Maybe worthy of a blog
post, once we settle this issue :-)


> > Only at that point can we then decide whether any of
> > the proposed "solutions" (in quotes because I remain unconvinced
> > there's a problem to solve here other than working around compiler
> > bugs) is/are necessary _and_ fulfilling the purpose, and if multiple
> > remain, which of them we like best / is the least bad one.
> 
> Improvements this series seeks to make, as I understand it, include
> (in order of urgency):
> 
> 1. Fixing one concrete instance of "UB hazard"
> 2. Minimize risk of further "UB hazard" in this bit of functionality
> 3. Retain the effort Stefano has put in identifying all the places
> where such UB hazards need to be addressed.
> 4. Move towards MISRA-C compliance.

This is exactly right.


> As far as I can tell, primary objections you've leveled at the options
> which try to address 2-4 are:
> 
> a. "UB hazard" still not zero
> b. MISRA compliancy no 100%
> c. Ugly
> d. Inefficient
> 
> (Obviously some proposals have had more technical discussion.)
> 
> Anything I missed?

I would like to add here the reply I got from the MISRAC experts, that
matches your view above.

Predictably, they dislike both SYMBOL_HIDE workarounds, because they are
just compiler workarounds rather than compliance and/or code
improvements.

Instead, they suggest an approach very similar to the var.S approach,
but simpler, without the assembly redirection. Their suggestion is to
declare uintptr_t variables in C corresponding to the linker symbols and
initialize them _once_ to the linker symbol values:

  /* linker symbols */
  extern char _start[], _end[];
  /* corresponding uintptr_t variables in C */
  uintptr_t start, end;

  /* initialization of the uintptr_t variables */
  start = (uintptr_t) _start;
  end = (uintptr_t) _end;
  
  /* example usage */
  size = (_end - _start);


Thus, I think it is best to follow-up on the var.S approach. Whether we
declare the variables in assembly in var.S or in a C file like
suggested, is a minor detail.

But before I proceed in reworking the series once more, I would like to
get an agreement on the way forward. I don't think Jan's solution is
good enough, but I am willing to follow through with it if that's the
decision. But I would really love to avoid sending yet another series
update whose fundamental approach gets rejected again.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  reply	other threads:[~2019-02-01 20:53 UTC|newest]

Thread overview: 102+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-09 23:41 [PATCH v6 0/4] misc safety certification fixes Stefano Stabellini
2019-01-09 23:42 ` [PATCH v6 1/4] xen: introduce SYMBOL Stefano Stabellini
2019-01-10  2:40   ` Julien Grall
2019-01-10  8:24     ` Jan Beulich
2019-01-10 17:29       ` Stefano Stabellini
2019-01-10 18:46         ` Stewart Hildebrand
2019-01-10 19:03           ` Stefano Stabellini
2019-01-11 10:35           ` Jan Beulich
2019-01-11 17:01             ` Stefano Stabellini
2019-01-10 19:24         ` Julien Grall
2019-01-10 21:36           ` Stefano Stabellini
2019-01-10 23:31             ` Julien Grall
2019-01-11  2:14               ` Stefano Stabellini
2019-01-11  6:52                 ` Juergen Gross
2019-01-11 16:52                   ` Stefano Stabellini
2019-01-11 10:48                 ` Jan Beulich
2019-01-11 18:04                   ` Stefano Stabellini
2019-01-11 18:53                     ` Stewart Hildebrand
2019-01-11 20:35                       ` Julien Grall
2019-01-11 20:46                         ` Stewart Hildebrand
2019-01-11 21:37                           ` Stefano Stabellini
2019-01-14  3:45                             ` Stewart Hildebrand
2019-01-14 10:26                               ` Jan Beulich
2019-01-14 21:18                                 ` Stefano Stabellini
     [not found]                                   ` <1CACC1FB020000D800417A66@prv1-mh.provo.novell.com>
2019-01-15  8:21                                     ` Jan Beulich
2019-01-15 11:51                                       ` Julien Grall
     [not found]                                         ` <AB1DA25B020000B95C475325@prv1-mh.provo.novell.com>
2019-01-15 12:04                                           ` Jan Beulich
2019-01-15 12:23                                             ` Julien Grall
     [not found]                                               ` <BAE986750200003A5C475325@prv1-mh.provo.novell.com>
2019-01-15 12:44                                                 ` Jan Beulich
2019-01-15 20:03                                       ` Stewart Hildebrand
2019-01-16  6:01                                         ` Juergen Gross
2019-01-16 10:19                                         ` Jan Beulich
2019-01-17  0:37                                           ` Stefano Stabellini
     [not found]                                             ` <B4D3ABC30200003B88BF86FB@prv1-mh.provo.novell.com>
     [not found]                                               ` <529ED2F90200004D00417A66@prv1-mh.provo.novell.com>
2019-01-17 11:45                                                 ` Jan Beulich
2019-01-18  1:24                                                   ` Stefano Stabellini
     [not found]                                                     ` <76A2DEED0200005600417A66@prv1-mh.provo.novell.com>
2019-01-18  9:54                                                       ` Jan Beulich
2019-01-18 10:48                                                         ` Julien Grall
     [not found]                                                           ` <9F511FC70200005E5C475325@prv1-mh.provo.novell.com>
2019-01-18 11:09                                                             ` Jan Beulich
2019-01-18 15:22                                                               ` Julien Grall
     [not found]                                                                 ` <3A8206D8020000035C475325@prv1-mh.provo.novell.com>
2019-01-21  9:39                                                                   ` Jan Beulich
2019-01-21  9:34                                                             ` Jan Beulich
2019-01-21 10:22                                                               ` Julien Grall
     [not found]                                                                 ` <E16AB350020000435C475325@prv1-mh.provo.novell.com>
2019-01-21 10:31                                                                   ` Jan Beulich
2019-01-21 23:15                                                                     ` Stefano Stabellini
     [not found]                                                                       ` <5EA2B4FA0200008000417A66@prv1-mh.provo.novell.com>
2019-01-22  9:06                                                                         ` Jan Beulich
2019-01-18 23:05                                                         ` Stefano Stabellini
2019-01-21  5:24                                                           ` Stewart Hildebrand
     [not found]                                                           ` <5A96F2FD0200008D00417A66@prv1-mh.provo.novell.com>
2019-01-21  9:50                                                             ` Jan Beulich
2019-01-21 23:41                                                               ` Stefano Stabellini
2019-01-22  6:08                                                                 ` Juergen Gross
     [not found]                                                                 ` <42A2C4FA0200009000417A66@prv1-mh.provo.novell.com>
2019-01-22  9:16                                                                   ` Jan Beulich
2019-02-01 18:52                                                                     ` George Dunlap
2019-02-01 20:53                                                                       ` Stefano Stabellini [this message]
     [not found]                                                             ` <58377FAD0200004688BF86FB@prv1-mh.provo.novell.com>
2019-01-21 10:06                                                               ` Jan Beulich
2019-02-06 15:41                                                                 ` Ian Jackson
     [not found]                                           ` <C8F95655020000CAB8D7C7D4@prv1-mh.provo.novell.com>
     [not found]                                             ` <5867EFE6020000DB00417A66@prv1-mh.provo.novell.com>
     [not found]                                               ` <DACE7A5F020000B1B8D7C7D4@prv1-mh.provo.novell.com>
2019-02-07 14:51                                                 ` Jan Beulich
2019-01-15 23:36                                       ` Stefano Stabellini
2019-01-16  8:47                                         ` Juergen Gross
     [not found]                                         ` <2EA6D6FD0200001F00417A66@prv1-mh.provo.novell.com>
2019-01-16 10:25                                           ` Jan Beulich
2019-01-17  0:41                                             ` Stefano Stabellini
     [not found]                                               ` <4EA2F2F90200004D00417A66@prv1-mh.provo.novell.com>
2019-01-17 11:46                                                 ` Jan Beulich
     [not found]                                     ` <95DC675902000028AB59E961@prv1-mh.provo.novell.com>
2019-02-04  9:37                                       ` Jan Beulich
2019-02-04 19:08                                         ` Stefano Stabellini
2019-02-05  6:02                                           ` Juergen Gross
     [not found]                                           ` <2E9DDEFD0200007B00417A66@prv1-mh.provo.novell.com>
2019-02-05  7:53                                             ` Jan Beulich
2019-02-05 14:56                                         ` George Dunlap
     [not found]                                           ` <E730A9F90200001DAB59E961@prv1-mh.provo.novell.com>
2019-02-06 11:59                                             ` Jan Beulich
     [not found]                                 ` <7A8C0A4F020000EEB8D7C7D4@prv1-mh.provo.novell.com>
2019-02-06 16:21                                   ` Jan Beulich
2019-02-06 16:37                                     ` Ian Jackson
     [not found]                                       ` <08D440470200001BB8D7C7D4@prv1-mh.provo.novell.com>
2019-02-06 16:47                                         ` Jan Beulich
2019-02-06 16:52                                           ` Ian Jackson
2019-02-06 23:39                                             ` Stefano Stabellini
2019-02-07 11:48                                               ` Ian Jackson
2019-02-07 18:18                                                 ` Stefano Stabellini
2019-02-12 11:31                                                   ` Ian Jackson
2019-02-13  0:09                                                     ` Stefano Stabellini
2019-01-15 11:46                             ` Julien Grall
2019-01-15 12:23                               ` Julien Grall
2019-01-14 10:11                     ` Jan Beulich
2019-01-14 15:41                       ` Julien Grall
2019-01-14 15:52                         ` Jan Beulich
2019-01-14 16:26                           ` Stewart Hildebrand
2019-01-14 16:39                             ` Jan Beulich
2019-01-14 16:28                           ` Julien Grall
2019-01-14 16:44                             ` Jan Beulich
2019-01-14 17:24                               ` Julien Grall
2019-01-15  8:04                                 ` Jan Beulich
2019-01-10 17:22     ` Stefano Stabellini
2019-01-10  8:34   ` Jan Beulich
2019-01-10 18:09     ` Stefano Stabellini
2019-01-09 23:42 ` [PATCH v6 2/4] xen/arm: use SYMBOL when required Stefano Stabellini
2019-01-10  8:41   ` Jan Beulich
2019-01-10 17:44     ` Stefano Stabellini
2019-01-11 10:52       ` Jan Beulich
2019-01-11 16:58         ` Stefano Stabellini
2019-01-14  9:23           ` Jan Beulich
2019-01-09 23:42 ` [PATCH v6 3/4] xen/x86: " Stefano Stabellini
2019-01-10  8:43   ` Jan Beulich
2019-01-10 17:45     ` Stefano Stabellini
2019-01-09 23:42 ` [PATCH v6 4/4] xen/common: " Stefano Stabellini
2019-01-10  8:49   ` Jan Beulich
2019-01-10 17:48     ` Stefano Stabellini

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=alpine.DEB.2.10.1902011239120.22962@sstabellini-ThinkPad-X260 \
    --to=sstabellini@kernel.org \
    --cc=JBeulich@suse.com \
    --cc=Stewart.Hildebrand@dornerworks.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dunlapg@umich.edu \
    --cc=jgross@suse.com \
    --cc=julien.grall@arm.com \
    --cc=julien.grall@gmail.com \
    --cc=stefanos@xilinx.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /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.