[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3] livepatch: account for patch offset when applying NOP patch
- To: Jan Beulich <jbeulich@xxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>
- From: Ross Lagerwall <ross.lagerwall@xxxxxxxxxx>
- Date: Thu, 7 Apr 2022 15:44:16 +0000
- Accept-language: en-US
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=RJSCYQC13VBjLksu7bWsgiNW2ZBpgAQuRX+6zZqKSvo=; b=EP/t3eemlMUKvcJ4HszO5ysVWpXiV0dT5zcOIHcrpRDkESyjly8cWGyhrJyyUnjky77mX+NsKoGCk9P/oXZe4MylqXqqz/4MufffPjgR7HMcHfAYHFiuRCxBdjKOtF4wI/qpAGU4LMmVlBznid5wmgc2werjnIdGc1zRWKubBKDLiQnV7KnGiZIuT2BM/jGb+PDmtIcn39VLDqNZa9WaRwcWSoutju0NtjBh+huv935NkbS7oCCWXre1qeOtLO9KubgY2v01BdBnoiubud415jy/RWUtXIeqSHVVR5mOK+bfhRoQuWUF0UnEB/WTibLH7xxefUrTyuG5NIuwpNDtRA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fw9FNh8iApjWXIGYXYv11VCegtFpLsh4KsyW6MTQVhMUs9GQcRA4NKkJ/h0dT+IrtoceWyB1fnV2WPX/38P3jxV93nBUI3E2vF/1ssshuwxDEx+3iNVgshd9yYp/iRFtRtyaetPP0EfkBE5ly1wwy/+rnAeWlqZRnj+AA/gY3TWhmVk/4RId6AxDbozAFZR2c88DqwvJvEpoS9E9ZuAgjQP1QAlAd2flHPM/iTBGk22l9C2y8Wg2JYLHILPBZ/Rk4LYDjOHWvcmhxhTpriCNEI6dhQFgm1FQm7oEzPmFvWfJ2V1d2OWoypVWuUTd0RJ9sX/DT8Wjml57wYch60rVeg==
- Authentication-results: esa4.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
- Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Konrad Wilk" <konrad.wilk@xxxxxxxxxx>, Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>, "Wei Liu" <wl@xxxxxxx>, Bjoern Doebel <doebel@xxxxxxxxx>
- Delivery-date: Thu, 07 Apr 2022 15:44:36 +0000
- Ironport-data: A9a23:eP1Me682pNkDedtlFCbSDrUDRX6TJUtcMsCJ2f8bNWPcYEJGY0x3m 2seD2mBM6yIYmGkLY9/aou//BkHuZfRzd4wHlBu+Ss8E34SpcT7XtnIdU2Y0wF+jyHgoOCLy +1EN7Es+ehtFie0Si+Fa+Sn9T8mvU2xbuKU5NTsY0idfic5DnZ54f5fs7Rh2NQw3YDmW1nlV e7a+KUzBnf0g1aYDUpMg06zgEsHUCPa4W5wUvQWPJinjXeG/5UnJMt3yZKZdhMUdrJ8DO+iL 9sv+Znilo/vE7XBPfv++lrzWhVirrc/pmFigFIOM0SpqkAqSiDfTs/XnRfTAKtao2zhojx/9 DlCnYbsbyUCfYr9pOU+fxh4Oh1vAJBW0rCSdBBTseTLp6HHW37lwvEoB0AqJ4wIvO1wBAmi9 9RBdmpLNErawbvrnvTrEYGAhex6RCXvFJkYoWomyTjWAOw5SJTHa67L+cVZzHE7gcUm8fP2O JJHOWA+MUmojxtnF0wQN4Azm8uS1lr2KSVlrmjPnLUuyj2GpOB2+Oe0a4eEEjCQfu1Kmm6Iq 2SA+H72ajkWM9GVxD6t+3ellOjJ2y/2MKoRE7ui//Isn1yXxUQUEhQdUVb9qv684ma8Ud9CL 00f+gI1sLM/skesS7HVTxC+5XKJoBMYc95RCPEhrhGAzLLO5ASUDXRCSSROAOHKr+dvG2Zsj AXQ2Yq0W3o/69V5VE5x6J+O8RWQEmsyHFMDRgMFbSI58uTesKs820enoslYLIa5idj8GDfVy j+MrTQji7h7sfPnx5lX7nic3Wvy+8Ghohodo1yOAzn7tl8RiJuNPdTA1LTN0RpXwG91pHGlt WNMpcWR5ftm4XqlxH3UG7Vl8F1ECp+43NzgbbxHQsFJG9eFoSfLkWVsDNdWfhoB3iEsI2KBX aMrkVkNjKK/xVPzBUONX6q/Ct4x0Y/rHsn/W/bfY7JmO8YtJVXXoXw+OhHJhggBdXTAd4llZ P93lu72Ux4n5VlPlmLqF4/xL5d1rszB+Y8jbc+ilEn2uVZvTHWUVa0EIDOzghMRt8u5TPHu2 48HbaOikkwHOMWnO3W/2dNDfDgicClgbbir+pM/SwJ2Clc/cI3XI6SKmu1Jlk0Mt/k9q9okC VnhAhQIlwel3SSvxMfjQikLVY4DlK1X9BoTFSctIUypyz4kZ4Ou570YbJw5Yf8s8+kL8BK+Z 6BtlxmoahiXdgn6xg==
- Ironport-hdrordr: A9a23:btlffK5fGIxiudkNIQPXwCbXdLJyesId70hD6qm+c20uTiX4rb HSoB1/73XJYVkqKRcdcLy7Sc69qDbnhPpICOoqTNWftWvdyRKVxehZhOOIrlHd8m/Fh4tgPM xbAtBD4bPLfCNHZAXBjjVQ0exO/DBKysCVrNab6WxsQ0VLUshbnnlEIzfeK1ZxQgZeA5o/Cd 6z2uprzgDQBUg/X4CDHX8CUPHEp9rX0LTcQTBDKSIGxWC1/EyVAJiTKWno4v7WaVI/oosfzQ ==
- List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
- Msip_labels:
- Thread-index: AQHYRMuYkv/j9QPlc0OOPsJ/our1NqzZJyyAgAAFroCAC27ZFg==
- Thread-topic: [PATCH v3] livepatch: account for patch offset when applying NOP patch
> From: Jan Beulich <jbeulich@xxxxxxxx>
> Sent: Thursday, March 31, 2022 9:42 AM
> To: Roger Pau Monne <roger.pau@xxxxxxxxxx>
> Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx <xen-devel@xxxxxxxxxxxxxxxxxxxx>; Ross
> Lagerwall <ross.lagerwall@xxxxxxxxxx>; Konrad Wilk <konrad.wilk@xxxxxxxxxx>;
> Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>; Wei Liu <wl@xxxxxxx>; Bjoern
> Doebel <doebel@xxxxxxxxx>
> Subject: Re: [PATCH v3] livepatch: account for patch offset when applying NOP
> patch
>
> [CAUTION - EXTERNAL EMAIL] DO NOT reply, click links, or open attachments
> unless you have verified the sender and know the content is safe.
>
> On 31.03.2022 10:21, Roger Pau Monné wrote:
> > On Thu, Mar 31, 2022 at 08:49:46AM +0200, Jan Beulich wrote:
> >> While not triggered by the trivial xen_nop in-tree patch on
> >> staging/master, that patch exposes a problem on the stable trees, where
> >> all functions have ENDBR inserted. When NOP-ing out a range, we need to
> >> account for this. Handle this right in livepatch_insn_len().
> >>
> >> This requires livepatch_insn_len() to be called _after_ ->patch_offset
> >> was set.
> >>
> >> Fixes: 6974c75180f1 ("xen/x86: Livepatch: support patching CET-enhanced
> >> functions")
> >> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> >
> > Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
>
> Thanks.
>
> As a note to the livepatch maintainers: I'm going to put this in
> without further waiting for suitable acks. Just in case I'll put
> it on the 4.16 branch only for starters, to see that it actually
> helps there (it's unusual to put something on the stable
> branches before it having passed the push gate to master).
Thanks (was on PTO and away from email).
>
> > Albeit I don't think I understand how the in-place patching is done. I
> > would expect the !func->new_addr branch of the if in
> > arch_livepatch_apply to fill the insn buffer with the in-place
> > replacement instructions, but I only see the buffer getting filled
> > with nops. I'm likely missing something (not that this patch changes
> > any of this).
>
> Well, as per the v2 thread: There's no in-place patching except
> to NOP out certain insns.
Correct. FWIW I'm not really aware of a valid use case for this
>
> > I'm also having trouble figuring out how we assert that the len value
> > (which is derived from new_size if !new_addr) is not greater than
> > LIVEPATCH_OPAQUE_SIZE, which is the limit of the insn buffer. Maybe
> > that's already checked elsewhere.
>
> That's what my 3rd post-commit-message remark was (partly) about.
old_size specifies the length of the existing function to be patched.
If new_addr is zero (NOP case), then new_size specifies the number of
bytes to overwrite with NOP. That's why new_size is used as the memcpy
length (minus patch offset). It is checked against the size of the insn
buffer in arch_livepatch_verify_func(). I think the code is correct as is
but I could be missing something.
Ross
|