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=-15.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 53C66C433B4 for ; Thu, 13 May 2021 10:16:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1C46F60BBB for ; Thu, 13 May 2021 10:16:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232454AbhEMKRt (ORCPT ); Thu, 13 May 2021 06:17:49 -0400 Received: from pegase2.c-s.fr ([93.17.235.10]:56307 "EHLO pegase2.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232063AbhEMKRr (ORCPT ); Thu, 13 May 2021 06:17:47 -0400 Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4Fgncz44FZz9sch; Thu, 13 May 2021 12:16:35 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id elzAeS9dJuuJ; Thu, 13 May 2021 12:16:35 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4Fgncz368bz9scg; Thu, 13 May 2021 12:16:35 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 313FE8B7F3; Thu, 13 May 2021 12:16:35 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id R8jvyF-796Mk; Thu, 13 May 2021 12:16:35 +0200 (CEST) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B59358B76C; Thu, 13 May 2021 12:16:34 +0200 (CEST) Subject: Re: [PATCH 8/8] xen/hvc: replace BUG_ON() with negative return value To: Juergen Gross , xen-devel@lists.xenproject.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , Jiri Slaby References: <20210513100302.22027-1-jgross@suse.com> <20210513100302.22027-9-jgross@suse.com> From: Christophe Leroy Message-ID: <6da4cc91-ccde-fce8-707c-e7544783c2fa@csgroup.eu> Date: Thu, 13 May 2021 12:16:35 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210513100302.22027-9-jgross@suse.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Le 13/05/2021 à 12:03, Juergen Gross a écrit : > Xen frontends shouldn't BUG() in case of illegal data received from > their backends. So replace the BUG_ON()s when reading illegal data from > the ring page with negative return values. > > Signed-off-by: Juergen Gross > --- > drivers/tty/hvc/hvc_xen.c | 15 +++++++++++++-- > 1 file changed, 13 insertions(+), 2 deletions(-) > > diff --git a/drivers/tty/hvc/hvc_xen.c b/drivers/tty/hvc/hvc_xen.c > index 92c9a476defc..30d7ffb1e04c 100644 > --- a/drivers/tty/hvc/hvc_xen.c > +++ b/drivers/tty/hvc/hvc_xen.c > @@ -86,6 +86,11 @@ static int __write_console(struct xencons_info *xencons, > cons = intf->out_cons; > prod = intf->out_prod; > mb(); /* update queue values before going on */ > + > + if (WARN_ONCE((prod - cons) > sizeof(intf->out), > + "Illegal ring page indices")) > + return -EINVAL; > + > BUG_ON((prod - cons) > sizeof(intf->out)); Why keep the BUG_ON() ? > > while ((sent < len) && ((prod - cons) < sizeof(intf->out))) > @@ -114,7 +119,10 @@ static int domU_write_console(uint32_t vtermno, const char *data, int len) > */ > while (len) { > int sent = __write_console(cons, data, len); > - > + > + if (sent < 0) > + return sent; > + > data += sent; > len -= sent; > > @@ -138,7 +146,10 @@ static int domU_read_console(uint32_t vtermno, char *buf, int len) > cons = intf->in_cons; > prod = intf->in_prod; > mb(); /* get pointers before reading ring */ > - BUG_ON((prod - cons) > sizeof(intf->in)); > + > + if (WARN_ONCE((prod - cons) > sizeof(intf->in), > + "Illegal ring page indices")) > + return -EINVAL; > > while (cons != prod && recv < len) > buf[recv++] = intf->in[MASK_XENCONS_IDX(cons++, intf->in)]; >