From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99540C433FF for ; Mon, 5 Aug 2019 13:25:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 70CCC2075B for ; Mon, 5 Aug 2019 13:25:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565011520; bh=A2eYit4iCgSv7faV4aJTnohGLCKHnrfaYjk0Q0752e4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=K/OwgaNGjT8FuNDRq2HcMtwnPxLED1dTF5LTti/ONKIh4nR0Sno9pIbD4rSDswK+6 /XTDZucL8ch5dVUdNPlY0V2fzuM5oBv3vqT6mnXQAI/zq0aAead/FDLjI75HoXJfdc tyAZxpRjLh0mRV7BKavhYC+z8R+FeLDLvPuvE3qA= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729298AbfHENZT (ORCPT ); Mon, 5 Aug 2019 09:25:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:33756 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730801AbfHENZQ (ORCPT ); Mon, 5 Aug 2019 09:25:16 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 02A4E2067D; Mon, 5 Aug 2019 13:25:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565011515; bh=A2eYit4iCgSv7faV4aJTnohGLCKHnrfaYjk0Q0752e4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=woqr8ywiCxBh5hYaWDKdFVKqdNuFqMSqS4yMvE1+Xw1rkb1LkFqNhX+T+G0Pnb6SI LGp4mm+Ii+fzTfsnFvq7GHiuyt7N35AKwxh+Z/pGg98Tmc+9xu2fhqjoWJ16Abr2/Y uHhov6z9WuzEq/H0H+zOlbjKFxhuL1sa98C/ad2s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Juergen Gross , Boris Ostrovsky , Jan Beulich , Konrad Rzeszutek Wilk Subject: [PATCH 5.2 118/131] xen/swiotlb: fix condition for calling xen_destroy_contiguous_region() Date: Mon, 5 Aug 2019 15:03:25 +0200 Message-Id: <20190805124959.859269321@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190805124951.453337465@linuxfoundation.org> References: <20190805124951.453337465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Juergen Gross commit 50f6393f9654c561df4cdcf8e6cfba7260143601 upstream. The condition in xen_swiotlb_free_coherent() for deciding whether to call xen_destroy_contiguous_region() is wrong: in case the region to be freed is not contiguous calling xen_destroy_contiguous_region() is the wrong thing to do: it would result in inconsistent mappings of multiple PFNs to the same MFN. This will lead to various strange crashes or data corruption. Instead of calling xen_destroy_contiguous_region() in that case a warning should be issued as that situation should never occur. Cc: stable@vger.kernel.org Signed-off-by: Juergen Gross Reviewed-by: Boris Ostrovsky Reviewed-by: Jan Beulich Acked-by: Konrad Rzeszutek Wilk Signed-off-by: Juergen Gross Signed-off-by: Greg Kroah-Hartman --- drivers/xen/swiotlb-xen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/drivers/xen/swiotlb-xen.c +++ b/drivers/xen/swiotlb-xen.c @@ -361,8 +361,8 @@ xen_swiotlb_free_coherent(struct device /* Convert the size to actually allocated. */ size = 1UL << (order + XEN_PAGE_SHIFT); - if (((dev_addr + size - 1 <= dma_mask)) || - range_straddles_page_boundary(phys, size)) + if (!WARN_ON((dev_addr + size - 1 > dma_mask) || + range_straddles_page_boundary(phys, size))) xen_destroy_contiguous_region(phys, order); xen_free_coherent_pages(hwdev, size, vaddr, (dma_addr_t)phys, attrs);