Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2946072pxj; Mon, 10 May 2021 14:37:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfdCyf6IB6GfEZYTQjZZZEnoGNuOX3iM+LbuE1wN68BBqfeX0qxbfpnz4XBJ9FZ0tXq0PT X-Received: by 2002:a92:c54b:: with SMTP id a11mr9498510ilj.174.1620682640195; Mon, 10 May 2021 14:37:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620682640; cv=none; d=google.com; s=arc-20160816; b=iahunM/Xpboki15SRA7zSi7KakQuuJk/CHRdlcVW3ngAI9VxuAN308V8LDyhSmlgvc qPMzI/aMoauk9E3a10/xfU6j8Vh4KTaMZIMgcQbAz3vojwL7OHY0iwGTtX1afIkqZBX/ t2vYWhfUD580jEcbCQgapfhhqcYFnG4y+msJtrgUthDsEFdWmEbJj+d0Jnj4owMupqvZ L+uO2pkF0NAyyN1LGxrHsqWgqCQKreqZnxnV4eG0Nz0JKlYyoE8U/oYYBs8R+Wlp+btO c7YfST5gBz8zMvgmOktYOwLFMyTWir4aXQhgHOFFFVp1VNTFyFCn594smBuJB5Wq61rT zBeg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=DiFiqsL6GZO/eOvxcnkj+3aRr/UkE0/U9/Sa046Xvks=; b=BjjpSZSFNs+MVEDgQ54f/CgRgUW/f/n9pYmBncMnRAxWVbZICx/wpyMYY/08qZ+92Z aNLFw9bhb2AbRB8u1fnaelosCqM16R4J8OhHXDohuqvSg/x0S2d2cX/FFhKuFg6o3BXz WANkvWSUWis5DTvzGRmHIxDhXXRAQ+SQ0Fx8R1piy7Kr/Zp0mud/8C2hqZbMReIg5ebD 9QbECTjbfC8jXdhApIcieMCBX/rGVYJkkSQwq6Wvi3MjomBcRy6w15E6AbKDbY2uEZU4 /pe8kBCVaxnNa0zVo+qHr/i95GJdux4bFUXIbYyYxvJbHZ8dLI17XtkO3siNMY14Cu+H 2UHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h25si15619608jam.40.2021.05.10.14.37.07; Mon, 10 May 2021 14:37:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231617AbhEJVho (ORCPT + 99 others); Mon, 10 May 2021 17:37:44 -0400 Received: from gate.crashing.org ([63.228.1.57]:57318 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230165AbhEJVhn (ORCPT ); Mon, 10 May 2021 17:37:43 -0400 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 14ALElMY017988; Mon, 10 May 2021 16:14:47 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 14ALEiiv017985; Mon, 10 May 2021 16:14:44 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Mon, 10 May 2021 16:14:44 -0500 From: Segher Boessenkool To: Christophe Leroy Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , pmenzel@molgen.mpg.de, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] powerpc/legacy_serial: Fix UBSAN: array-index-out-of-bounds Message-ID: <20210510211444.GE10366@gate.crashing.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, May 08, 2021 at 06:36:21AM +0000, Christophe Leroy wrote: > UBSAN complains when a pointer is calculated with invalid > 'legacy_serial_console' index, allthough the index is verified > before dereferencing the pointer. Addressing like this is UB already. You could just move this: > - if (legacy_serial_console < 0) > - return 0; to before > - struct legacy_serial_info *info = &legacy_serial_infos[legacy_serial_console]; > - struct plat_serial8250_port *port = &legacy_serial_ports[legacy_serial_console]; and no other change is necessary. Segher