Received: by 10.223.176.5 with SMTP id f5csp1593662wra; Sun, 4 Feb 2018 07:36:58 -0800 (PST) X-Google-Smtp-Source: AH8x225DjdYVLkJcGgcRaccv/p79Ngntkkt7HnQ00AgZmeFfgaROdCmP8mXW/2GSHaGALmCQpLoJ X-Received: by 10.101.102.3 with SMTP id w3mr36143366pgv.326.1517758617915; Sun, 04 Feb 2018 07:36:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517758617; cv=none; d=google.com; s=arc-20160816; b=ytsxz3O8G4byu+8g+40aykIkCx3+0p6N0mvgmr0t0rEfA0Ndi1yijG0WqF0VCJzyC6 Tcw87lCdORQumFmbk9ClAoF95tp8dx2WHytH2F9QrcCa4B/Vgwu8FrZHlW8u4uYhEC71 6yTZ5fU/3/67RRDkLi/KX8+gjsQ4x+/WqL7FDZzYaDZKbS35CItNaxMwPgZYXIUJDfUW cY5reolCJs29Wb0ekQBbEIXdU/KwPe7oXXz5roC1eV46Mdvx4bTiUNHxYqtz/Y74Ilop psYSW4R5kWBPoVV0v7WHaN+nWk+4xkEXtABa2eq/HCAjOWQ8rpE/oBxvNk5+1rq3Y/D+ xNfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=KuHM2YdAhBFE3k1rN3AX72MtComjwtS7BGVzFk+X6os=; b=xo5khs5+/c6brv0FwrN04UZN9fJBwRw+rhqKATWvxR+nHhnsp2Voh+rOqgUcu9Nz8C z50Op89z5Fn2IsukLx07F9t9AndBg4EQICGOphDTccPVZkXZY/Wp2UMW3NvDTaYYVWxz k/ffYTbnB5/FpQGpEpc56Ub1JudI1/9HeNoUboZu/eL6erENpl2BjDPC15P0peMQzVrF O0fuMZE67+BCG57WWLjERQJT3OQ+/z8mOPnuLokca/AnRnpU3UtM6KRMpCy+WoJBlURS Un2IDqWWjit47NT2vhJmbiE0tV8wJ+iVJU8IJLMPFDC4J40fujghWVNIexaYGqCO4yKn baqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=aFBGmdeh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a9-v6si3283375pls.560.2018.02.04.07.36.42; Sun, 04 Feb 2018 07:36:57 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=aFBGmdeh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751979AbeBDPfU (ORCPT + 99 others); Sun, 4 Feb 2018 10:35:20 -0500 Received: from mail-oi0-f66.google.com ([209.85.218.66]:41239 "EHLO mail-oi0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750995AbeBDPfN (ORCPT ); Sun, 4 Feb 2018 10:35:13 -0500 Received: by mail-oi0-f66.google.com with SMTP id m83so19528595oik.8 for ; Sun, 04 Feb 2018 07:35:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=KuHM2YdAhBFE3k1rN3AX72MtComjwtS7BGVzFk+X6os=; b=aFBGmdehos1Vgc6ob5yHKByOBuGNFV6UNO2opHXifFZ8S5W0NRmARc9pnohMzDCqx+ mBJon3TdVIlpZV4bL+Hgl/LkfQ2lY6xIPI29GqL9va4Tmr+Ap4ulCByt4JX4//RN55bv piuAzAqYhydFUVUPzvx7V0t+DVree9uEqTEUY39husj2ADIOamL/wD4gmUGq/vM7nM9M eotXSZfCddEO3G3ocJFOOtodbEhp7nhcbfhDeqqQq9C1mPgty/iR660sYmTFCwOERe0E SQlt4qQz44Id+1hO7VGXrnwtAWdTLxWLhYZ2BMxnctt+7BlUkowxL9mxIQIauacDaoZf msVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=KuHM2YdAhBFE3k1rN3AX72MtComjwtS7BGVzFk+X6os=; b=k73rlA4iOqX1KNMy0lFRRe5rvWKeeOhoMtN6s2h9spEBxjuE1CTZYxUitccpMVRvQU IIYGxqY+4fUl312YMPmH6Eu32y8rezvhy/882YwSprxVYGYblO7e6/pPU4TZ0swWlj3R TEYhAHA/w6tVSZy+LCrb7koW4W1z4Pm4a1T8+iTDKZWTOisgxdZc/yMGy2wWHC/31Xh6 A7uioTtO7z3fNQbuRbRvp9G0j7ZYCHxrtz45DLDQNUBzwMu15o1w6PB5sJAePJtY3Q7Z KQpG+w0/jhPjZ/mcGQl/Z+UuMaQ6O7ChCyVdl48U5sSrqV7kOuuCiXoyvbx1oo1qwf1r 2Gmg== X-Gm-Message-State: AKwxytc0++EunkPz5X4rnf4rEStm8SVN5hsVBBc0SFuG+Z8xNNopsFTQ sDwl2uIrvOjnxl8lrpQUaKv7gzksuNFXeRQPoK0= X-Received: by 10.202.83.194 with SMTP id h185mr19264102oib.228.1517758512123; Sun, 04 Feb 2018 07:35:12 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.68.33 with HTTP; Sun, 4 Feb 2018 07:35:11 -0800 (PST) In-Reply-To: <1e3424f4-771b-51ad-3630-0faf47e388e0@oracle.com> References: <20180202153240.1190361-1-arnd@arndb.de> <1e3424f4-771b-51ad-3630-0faf47e388e0@oracle.com> From: Arnd Bergmann Date: Sun, 4 Feb 2018 16:35:11 +0100 X-Google-Sender-Auth: FSIE0SHXn1e2tGx4_hF7l_r48sM Message-ID: Subject: Re: [PATCH] xen: hypercall: fix out-of-bounds memcpy To: Boris Ostrovsky Cc: Juergen Gross , Nicolas Pitre , Andi Kleen , Dan Carpenter , Jan Beulich , xen-devel , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Feb 3, 2018 at 6:08 PM, Boris Ostrovsky wrote: > > > On 02/03/2018 10:12 AM, Arnd Bergmann wrote: >> >> On Sat, Feb 3, 2018 at 12:33 AM, Boris Ostrovsky >> wrote: >>> >>> On 02/02/2018 10:32 AM, Arnd Bergmann wrote: >>>> >>>> The legacy hypercall handlers were originally added with >>>> a comment explaining that "copying the argument structures in >>>> HYPERVISOR_event_channel_op() and HYPERVISOR_physdev_op() into the local >>>> variable is sufficiently safe" and only made sure to not write >>>> past the end of the argument structure, the checks in linux/string.h >>>> disagree with that, when link-time optimizations are used: >>>> >>>> In function 'memcpy', >>>> inlined from 'pirq_query_unmask' at drivers/xen/fallback.c:53:2, >>>> inlined from '__startup_pirq' at >>>> drivers/xen/events/events_base.c:529:2, >>>> inlined from 'restore_pirqs' at >>>> drivers/xen/events/events_base.c:1439:3, >>>> inlined from 'xen_irq_resume' at >>>> drivers/xen/events/events_base.c:1581:2: >>>> include/linux/string.h:350:3: error: call to '__read_overflow2' declared >>>> with attribute error: detected read beyond size of object passed as 2nd >>>> parameter >>>> __read_overflow2(); >>>> ^ >>>> make[3]: *** [ccLujFNx.ltrans15.ltrans.o] Error 1 >>>> make[3]: Target 'all' not remade because of errors. >>>> lto-wrapper: fatal error: make returned 2 exit status >>>> compilation terminated. >>>> ld: error: lto-wrapper failed >>>> >>>> This changes the functions so that each argument is accessed with >>>> exactly the correct length based on the command code. >>>> >>>> Fixes: cf47a83fb06e ("xen/hypercall: fix hypercall fallback code for >>>> very old hypervisors") >>>> Signed-off-by: Arnd Bergmann >>>> --- >>>> drivers/xen/fallback.c | 94 >>>> ++++++++++++++++++++++++++++---------------------- >>>> 1 file changed, 53 insertions(+), 41 deletions(-) >>>> >> >>>> default: >>>> - WARN_ON(rc != -ENOSYS); >>>> - break; >>>> + return -ENOSYS; >>>> } >>>> >>>> + memcpy(&op.u, arg, len); >>>> + rc = _hypercall1(int, event_channel_op_compat, &op); >>>> + memcpy(arg, &op.u, len); >>> >>> >>> >>> We don't copy back for all commands, only those that are COPY_BACK. >> >> >> Not sure what you mean. Is it harmful to copy back the data for the others >> in any way? Otherwise I wouldn't micro-optimize this. > > > > I should have checked the original commit for fallback.c --- the code that > it replaced was doing copybacks for all hypercalls and selective copybacks > is an optimization introduced in that commit. It was not an optimization but a correctness fix to avoid overflowing the caller stack on the copy-back operation. What I tried to explain in my commit message is that the same fix is also needed on the copy-out before it. It's only a read access beyond the end of a local variable, but not both the static checks and kasan-stack get alarmed about it. Arnd