When the hypervisor was compiled in debug mode (with VERBOSE defined), PV guests incorrectly had access to both read and write to the console. Change this to only allow write access; since such writes were limited by log levels in 48d50de8e0, remove the dependency on VERBOSE completely. Reported-by: Jan Beulich <JBeulich@suse.com> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> --- Alternatively, if controlling writes with VERBOSE is still desired, the ifdef VERBOSE can be retained surrounding the if() with the following commit message: The CONSOLEIO_read operation was incorrectly allowed to PV guests if the hypervisor was compiled in debug mode (with VERBOSE defined). xen/include/xsm/dummy.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h index 052f3e0..1f4960d 100644 --- a/xen/include/xsm/dummy.h +++ b/xen/include/xsm/dummy.h @@ -221,11 +221,9 @@ static XSM_INLINE int xsm_memory_stat_reservation(XSM_DEFAULT_ARG struct domain static XSM_INLINE int xsm_console_io(XSM_DEFAULT_ARG struct domain *d, int cmd) { XSM_ASSERT_ACTION(XSM_OTHER); -#ifdef VERBOSE - return xsm_default_action(XSM_HOOK, current->domain, NULL); -#else - return xsm_default_action(XSM_PRIV, current->domain, NULL); -#endif + if ( cmd == CONSOLEIO_write ) + return xsm_default_action(XSM_HOOK, d, NULL); + return xsm_default_action(XSM_PRIV, d, NULL); } static XSM_INLINE int xsm_profile(XSM_DEFAULT_ARG struct domain *d, int op) -- 1.8.1.4
Daniel De Graaf
2013-Sep-30 15:48 UTC
[PATCH 2/2] xen/xsm: clean up unneeded current references
Some XSM hooks in dummy.h used current->domain when this was also passed as a parameter; use the parameter in these cases. There are two hooks where this does not apply and which are not immediately obvious: xsm_set_target''s parameters are the device model and HVM domains, and xsm_mem_sharing_op''s first parameter is the source of the shared page, not the domain making the hypercall. Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> --- xen/include/xsm/dummy.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h index 1f4960d..bde1c53 100644 --- a/xen/include/xsm/dummy.h +++ b/xen/include/xsm/dummy.h @@ -229,7 +229,7 @@ static XSM_INLINE int xsm_console_io(XSM_DEFAULT_ARG struct domain *d, int cmd) static XSM_INLINE int xsm_profile(XSM_DEFAULT_ARG struct domain *d, int op) { XSM_ASSERT_ACTION(XSM_HOOK); - return xsm_default_action(action, current->domain, NULL); + return xsm_default_action(action, d, NULL); } static XSM_INLINE int xsm_kexec(XSM_DEFAULT_VOID) @@ -279,7 +279,7 @@ static XSM_INLINE void xsm_evtchn_close_post(struct evtchn *chn) static XSM_INLINE int xsm_evtchn_send(XSM_DEFAULT_ARG struct domain *d, struct evtchn *chn) { XSM_ASSERT_ACTION(XSM_HOOK); - return xsm_default_action(action, current->domain, NULL); + return xsm_default_action(action, d, NULL); } static XSM_INLINE int xsm_evtchn_status(XSM_DEFAULT_ARG struct domain *d, struct evtchn *chn) -- 1.8.1.4
>>> On 30.09.13 at 17:48, Daniel De Graaf <dgdegra@tycho.nsa.gov> wrote: > When the hypervisor was compiled in debug mode (with VERBOSE defined), > PV guests incorrectly had access to both read and write to the console. > Change this to only allow write access; since such writes were limited > by log levels in 48d50de8e0, remove the dependency on VERBOSE > completely.I disagree, and iirc I disagreed already when you tried to drop the dependency on VERBOSE with that earlier patch.> Reported-by: Jan Beulich <JBeulich@suse.com> > Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> > --- > > Alternatively, if controlling writes with VERBOSE is still desired, the > ifdef VERBOSE can be retained surrounding the if() with the following > commit message: > > The CONSOLEIO_read operation was incorrectly allowed to PV guests if the > hypervisor was compiled in debug mode (with VERBOSE defined).That''s what I''d want to see go in. Jan> xen/include/xsm/dummy.h | 8 +++----- > 1 file changed, 3 insertions(+), 5 deletions(-) > > diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h > index 052f3e0..1f4960d 100644 > --- a/xen/include/xsm/dummy.h > +++ b/xen/include/xsm/dummy.h > @@ -221,11 +221,9 @@ static XSM_INLINE int > xsm_memory_stat_reservation(XSM_DEFAULT_ARG struct domain > static XSM_INLINE int xsm_console_io(XSM_DEFAULT_ARG struct domain *d, int > cmd) > { > XSM_ASSERT_ACTION(XSM_OTHER); > -#ifdef VERBOSE > - return xsm_default_action(XSM_HOOK, current->domain, NULL); > -#else > - return xsm_default_action(XSM_PRIV, current->domain, NULL); > -#endif > + if ( cmd == CONSOLEIO_write ) > + return xsm_default_action(XSM_HOOK, d, NULL); > + return xsm_default_action(XSM_PRIV, d, NULL); > } > > static XSM_INLINE int xsm_profile(XSM_DEFAULT_ARG struct domain *d, int op) > -- > 1.8.1.4
Daniel De Graaf
2013-Sep-30 17:29 UTC
Re: [PATCH 1/2] xen/xsm: forbid PV guest console reads
On 09/30/2013 12:10 PM, Jan Beulich wrote:>>>> On 30.09.13 at 17:48, Daniel De Graaf <dgdegra@tycho.nsa.gov> wrote: >> When the hypervisor was compiled in debug mode (with VERBOSE defined), >> PV guests incorrectly had access to both read and write to the console. >> Change this to only allow write access; since such writes were limited >> by log levels in 48d50de8e0, remove the dependency on VERBOSE >> completely. > > I disagree, and iirc I disagreed already when you tried to drop the > dependency on VERBOSE with that earlier patch. > >> Reported-by: Jan Beulich <JBeulich@suse.com> >> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> >> --- >> >> Alternatively, if controlling writes with VERBOSE is still desired, the >> ifdef VERBOSE can be retained surrounding the if() with the following >> commit message: >> >> > > That''s what I''d want to see go in. > > JanThis patch retains the existing behavior where only HVM guests can use the console for output, and only via the 0xE9 I/O port. With Konrad''s Linux patch, this means that xen_raw_console_write in non-dom0 will produce output only on Xen <= 4.3 (which returns -ENOSYS rather than -EPERM, as this code does). ------------------------8<---------------------------------------------- The CONSOLEIO_read operation was incorrectly allowed to PV guests if the hypervisor was compiled in debug mode (with VERBOSE defined). Reported-by: Jan Beulich <JBeulich@suse.com> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> --- xen/include/xsm/dummy.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h index 2abf018..b1edd29 100644 --- a/xen/include/xsm/dummy.h +++ b/xen/include/xsm/dummy.h @@ -233,10 +233,10 @@ static XSM_INLINE int xsm_console_io(XSM_DEFAULT_ARG struct domain *d, int cmd) { XSM_ASSERT_ACTION(XSM_OTHER); #ifdef VERBOSE - return xsm_default_action(XSM_HOOK, current->domain, NULL); -#else - return xsm_default_action(XSM_PRIV, current->domain, NULL); + if ( cmd == CONSOLEIO_write ) + return xsm_default_action(XSM_HOOK, d, NULL); #endif + return xsm_default_action(XSM_PRIV, d, NULL); } static XSM_INLINE int xsm_profile(XSM_DEFAULT_ARG struct domain *d, int op)
Konrad Rzeszutek Wilk
2013-Sep-30 18:06 UTC
Re: [PATCH 1/2] xen/xsm: forbid PV guest console reads
On Mon, Sep 30, 2013 at 01:29:00PM -0400, Daniel De Graaf wrote:> On 09/30/2013 12:10 PM, Jan Beulich wrote: > >>>>On 30.09.13 at 17:48, Daniel De Graaf <dgdegra@tycho.nsa.gov> wrote: > >>When the hypervisor was compiled in debug mode (with VERBOSE defined), > >>PV guests incorrectly had access to both read and write to the console. > >>Change this to only allow write access; since such writes were limited > >>by log levels in 48d50de8e0, remove the dependency on VERBOSE > >>completely. > > > >I disagree, and iirc I disagreed already when you tried to drop the > >dependency on VERBOSE with that earlier patch. > > > >>Reported-by: Jan Beulich <JBeulich@suse.com> > >>Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> > >>--- > >> > >>Alternatively, if controlling writes with VERBOSE is still desired, the > >>ifdef VERBOSE can be retained surrounding the if() with the following > >>commit message: > >> > >> > > > >That''s what I''d want to see go in. > > > >Jan > > This patch retains the existing behavior where only HVM guests can use > the console for output, and only via the 0xE9 I/O port. With Konrad''s > Linux patch, this means that xen_raw_console_write in non-dom0 will > produce output only on Xen <= 4.3 (which returns -ENOSYS rather than > -EPERM, as this code does).I was under the impression that what we wanted is: - normal PV guests can do console_write - HVM guests can do console_write - priv guests (irregardless if they are HVM or PV) can do console_write _and_ console_read. Which I think the patch below still allows right?> > ------------------------8<---------------------------------------------- > > The CONSOLEIO_read operation was incorrectly allowed to PV guests if the > hypervisor was compiled in debug mode (with VERBOSE defined). > > Reported-by: Jan Beulich <JBeulich@suse.com> > Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> > --- > xen/include/xsm/dummy.h | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h > index 2abf018..b1edd29 100644 > --- a/xen/include/xsm/dummy.h > +++ b/xen/include/xsm/dummy.h > @@ -233,10 +233,10 @@ static XSM_INLINE int xsm_console_io(XSM_DEFAULT_ARG struct domain *d, int cmd) > { > XSM_ASSERT_ACTION(XSM_OTHER); > #ifdef VERBOSE > - return xsm_default_action(XSM_HOOK, current->domain, NULL); > -#else > - return xsm_default_action(XSM_PRIV, current->domain, NULL); > + if ( cmd == CONSOLEIO_write ) > + return xsm_default_action(XSM_HOOK, d, NULL); > #endif > + return xsm_default_action(XSM_PRIV, d, NULL); > } > static XSM_INLINE int xsm_profile(XSM_DEFAULT_ARG struct domain *d, int op) >
Daniel De Graaf
2013-Sep-30 18:29 UTC
Re: [PATCH 1/2] xen/xsm: forbid PV guest console reads
On 09/30/2013 02:06 PM, Konrad Rzeszutek Wilk wrote:> On Mon, Sep 30, 2013 at 01:29:00PM -0400, Daniel De Graaf wrote: >> On 09/30/2013 12:10 PM, Jan Beulich wrote: >>>>>> On 30.09.13 at 17:48, Daniel De Graaf <dgdegra@tycho.nsa.gov> wrote: >>>> When the hypervisor was compiled in debug mode (with VERBOSE defined), >>>> PV guests incorrectly had access to both read and write to the console. >>>> Change this to only allow write access; since such writes were limited >>>> by log levels in 48d50de8e0, remove the dependency on VERBOSE >>>> completely. >>> >>> I disagree, and iirc I disagreed already when you tried to drop the >>> dependency on VERBOSE with that earlier patch. >>> >>>> Reported-by: Jan Beulich <JBeulich@suse.com> >>>> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> >>>> --- >>>> >>>> Alternatively, if controlling writes with VERBOSE is still desired, the >>>> ifdef VERBOSE can be retained surrounding the if() with the following >>>> commit message: >>>> >>>> >>> >>> That''s what I''d want to see go in. >>> >>> Jan >> >> This patch retains the existing behavior where only HVM guests can use >> the console for output, and only via the 0xE9 I/O port. With Konrad''s >> Linux patch, this means that xen_raw_console_write in non-dom0 will >> produce output only on Xen <= 4.3 (which returns -ENOSYS rather than >> -EPERM, as this code does). > > I was under the impression that what we wanted is: > - normal PV guests can do console_write > - HVM guests can do console_write > - priv guests (irregardless if they are HVM or PV) can do console_write > _and_ console_read. > > Which I think the patch below still allows right?All of your bullets are true if the hypervisor is compiled with VERBOSE (which is enabled if debug=y). Otherwise, only priv guests will be able to use console_write (and it won''t matter if they are PV or HVM). Either way, only priv guests will be able to use console_read - which is the only thing the below patch actually changes.>> >> ------------------------8<---------------------------------------------- >> >> The CONSOLEIO_read operation was incorrectly allowed to PV guests if the >> hypervisor was compiled in debug mode (with VERBOSE defined). >> >> Reported-by: Jan Beulich <JBeulich@suse.com> >> Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> >> --- >> xen/include/xsm/dummy.h | 6 +++--- >> 1 file changed, 3 insertions(+), 3 deletions(-) >> >> diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h >> index 2abf018..b1edd29 100644 >> --- a/xen/include/xsm/dummy.h >> +++ b/xen/include/xsm/dummy.h >> @@ -233,10 +233,10 @@ static XSM_INLINE int xsm_console_io(XSM_DEFAULT_ARG struct domain *d, int cmd) >> { >> XSM_ASSERT_ACTION(XSM_OTHER); >> #ifdef VERBOSE >> - return xsm_default_action(XSM_HOOK, current->domain, NULL); >> -#else >> - return xsm_default_action(XSM_PRIV, current->domain, NULL); >> + if ( cmd == CONSOLEIO_write ) >> + return xsm_default_action(XSM_HOOK, d, NULL); >> #endif >> + return xsm_default_action(XSM_PRIV, d, NULL); >> } >> static XSM_INLINE int xsm_profile(XSM_DEFAULT_ARG struct domain *d, int op) >> > >-- Daniel De Graaf National Security Agency
Konrad Rzeszutek Wilk
2013-Sep-30 19:26 UTC
Re: [PATCH 1/2] xen/xsm: forbid PV guest console reads
On Mon, Sep 30, 2013 at 02:29:57PM -0400, Daniel De Graaf wrote:> On 09/30/2013 02:06 PM, Konrad Rzeszutek Wilk wrote: > >On Mon, Sep 30, 2013 at 01:29:00PM -0400, Daniel De Graaf wrote: > >>On 09/30/2013 12:10 PM, Jan Beulich wrote: > >>>>>>On 30.09.13 at 17:48, Daniel De Graaf <dgdegra@tycho.nsa.gov> wrote: > >>>>When the hypervisor was compiled in debug mode (with VERBOSE defined), > >>>>PV guests incorrectly had access to both read and write to the console. > >>>>Change this to only allow write access; since such writes were limited > >>>>by log levels in 48d50de8e0, remove the dependency on VERBOSE > >>>>completely. > >>> > >>>I disagree, and iirc I disagreed already when you tried to drop the > >>>dependency on VERBOSE with that earlier patch. > >>> > >>>>Reported-by: Jan Beulich <JBeulich@suse.com> > >>>>Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> > >>>>--- > >>>> > >>>>Alternatively, if controlling writes with VERBOSE is still desired, the > >>>>ifdef VERBOSE can be retained surrounding the if() with the following > >>>>commit message: > >>>> > >>>> > >>> > >>>That''s what I''d want to see go in. > >>> > >>>Jan > >> > >>This patch retains the existing behavior where only HVM guests can use > >>the console for output, and only via the 0xE9 I/O port. With Konrad''s > >>Linux patch, this means that xen_raw_console_write in non-dom0 will > >>produce output only on Xen <= 4.3 (which returns -ENOSYS rather than > >>-EPERM, as this code does). > > > >I was under the impression that what we wanted is: > > - normal PV guests can do console_write > > - HVM guests can do console_write > > - priv guests (irregardless if they are HVM or PV) can do console_write > > _and_ console_read. > > > >Which I think the patch below still allows right? > > All of your bullets are true if the hypervisor is compiled with VERBOSE > (which is enabled if debug=y). Otherwise, only priv guests will be able > to use console_write (and it won''t matter if they are PV or HVM). Either > way, only priv guests will be able to use console_read - which is the > only thing the below patch actually changes.Good! That is how it should be :-)> > >> > >>------------------------8<---------------------------------------------- > >> > >>The CONSOLEIO_read operation was incorrectly allowed to PV guests if the > >>hypervisor was compiled in debug mode (with VERBOSE defined). > >> > >>Reported-by: Jan Beulich <JBeulich@suse.com> > >>Signed-off-by: Daniel De Graaf <dgdegra@tycho.nsa.gov> > >>--- > >> xen/include/xsm/dummy.h | 6 +++--- > >> 1 file changed, 3 insertions(+), 3 deletions(-) > >> > >>diff --git a/xen/include/xsm/dummy.h b/xen/include/xsm/dummy.h > >>index 2abf018..b1edd29 100644 > >>--- a/xen/include/xsm/dummy.h > >>+++ b/xen/include/xsm/dummy.h > >>@@ -233,10 +233,10 @@ static XSM_INLINE int xsm_console_io(XSM_DEFAULT_ARG struct domain *d, int cmd) > >> { > >> XSM_ASSERT_ACTION(XSM_OTHER); > >> #ifdef VERBOSE > >>- return xsm_default_action(XSM_HOOK, current->domain, NULL); > >>-#else > >>- return xsm_default_action(XSM_PRIV, current->domain, NULL); > >>+ if ( cmd == CONSOLEIO_write ) > >>+ return xsm_default_action(XSM_HOOK, d, NULL); > >> #endif > >>+ return xsm_default_action(XSM_PRIV, d, NULL); > >> } > >> static XSM_INLINE int xsm_profile(XSM_DEFAULT_ARG struct domain *d, int op) > >> > > > > > > > -- > Daniel De Graaf > National Security Agency