From patchwork Wed May 8 13:07:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 10935631 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7C73B1398 for ; Wed, 8 May 2019 13:08:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A43D1FE8A for ; Wed, 8 May 2019 13:08:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E29E20072; Wed, 8 May 2019 13:08:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 011161FE8A for ; Wed, 8 May 2019 13:08:46 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hOMIA-0006Pq-FM; Wed, 08 May 2019 13:07:26 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hOMI9-0006Pl-5A for xen-devel@lists.xenproject.org; Wed, 08 May 2019 13:07:25 +0000 X-Inumbo-ID: 3850499c-7192-11e9-843c-bc764e045a96 Received: from prv1-mh.provo.novell.com (unknown [137.65.248.33]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 3850499c-7192-11e9-843c-bc764e045a96; Wed, 08 May 2019 13:07:23 +0000 (UTC) Received: from INET-PRV1-MTA by prv1-mh.provo.novell.com with Novell_GroupWise; Wed, 08 May 2019 07:07:23 -0600 Message-Id: <5CD2D489020000780022CD34@prv1-mh.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 18.1.0 Date: Wed, 08 May 2019 07:07:21 -0600 From: "Jan Beulich" To: "xen-devel" References: <5CC6DD090200007800229E80@prv1-mh.provo.novell.com> <5CD2D2C8020000780022CCF2@prv1-mh.provo.novell.com> In-Reply-To: <5CD2D2C8020000780022CCF2@prv1-mh.provo.novell.com> Mime-Version: 1.0 Content-Disposition: inline Subject: [Xen-devel] [PATCH v2 03/12] x86/IRQ: avoid UB (or worse) in trace_irq_mask() X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: George Dunlap , Andrew Cooper , Wei Liu , Roger Pau Monne Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Dynamically allocated CPU mask objects may be smaller than cpumask_t, so copying has to be restricted to the actual allocation size. This is particulary important since the function doesn't bail early when tracing is not active, so even production builds would be affected by potential misbehavior here. Take the opportunity and also - use initializers instead of assignment + memset(), - constify the cpumask_t input pointer, - u32 -> uint32_t. Signed-off-by: Jan Beulich Reviewed-by: Roger Pau Monné Acked-by: George Dunlap --- v2: New. --- TBD: I wonder whether the function shouldn't gain an early tb_init_done check, like many other trace_*() have. George, despite your general request to be copied on entire series rather than individual patches, I thought it would be better to copy you on just this one (for its tracing aspect), as the patch here is independent of the rest of the series, but at least one later patch depends on the parameter constification done here. --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -104,16 +104,19 @@ static inline bool valid_irq_vector(unsi return vector >= FIRST_DYNAMIC_VECTOR && vector <= LAST_HIPRIORITY_VECTOR; } -static void trace_irq_mask(u32 event, int irq, int vector, cpumask_t *mask) +static void trace_irq_mask(uint32_t event, int irq, int vector, + const cpumask_t *mask) { struct { unsigned int irq:16, vec:16; unsigned int mask[6]; - } d; - d.irq = irq; - d.vec = vector; - memset(d.mask, 0, sizeof(d.mask)); - memcpy(d.mask, mask, min(sizeof(d.mask), sizeof(cpumask_t))); + } d = { + .irq = irq, + .vec = vector, + }; + + memcpy(d.mask, mask, + min(sizeof(d.mask), BITS_TO_LONGS(nr_cpu_ids) * sizeof(long))); trace_var(event, 1, sizeof(d), &d); }