Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp575674ybz; Wed, 22 Apr 2020 04:03:10 -0700 (PDT) X-Google-Smtp-Source: APiQypKx+bM9vHgFxqWyihiNRCJN+Ua5whR0cwj09/Ce803lnF/74QMSYZ2qg4pshPtzGmMe/6Xn X-Received: by 2002:a05:6402:17e3:: with SMTP id t3mr22997334edy.203.1587553390749; Wed, 22 Apr 2020 04:03:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587553390; cv=none; d=google.com; s=arc-20160816; b=DwW63UK2BrwReGCfLaxw3sp6ul7rHEkh//wsVfBWAZT4xGJ/sCh54drCsTMh6t+Jj4 cZFfphoE2RSypogAdSiKbcWSdzwhRDqPTQennfa89H+6PVPPZa7u/tDoGUhT+yija42T 8J+7FrM4147x3vnRw71EqragOvSQGFDOD8kMcJh39L3stu5iRicDieKkESL40dm6GwFO nEY+4POOAEyG8Wic3bZHXRxp6xNBcHw41GV9W35Q6/V6k6vyKJOdJf0hW2+gvhbR+w5H 2eBn3SCGc+7PvkzBXxrV21wlAFYX24nfGYiSLEPL1Wzd1MP3PpyH+7JRT14Labmv7f6z TOUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eDLhZ2XBW60oK/b+MMghKfbT2vgEAW4i/wnUQ/5DeJU=; b=c/nZgzGuOy90ffNoEsy3h0ROBKl2F3I904os7T1OuIsafF7D8minKMsU1rTtLH/tcc IZqvL2fXSmvkDLu5/3ANl4Kqsq5KFpQ+Z+KjsRdSWUny5ABdhX6aKwKqMeCg8jU0us80 qWKaK7dqildUFsXFVHUmrdVIFv1fsdHsvcAc6HscI8aRda8/0ejj2VtNxPtubRUQcmZ0 Cp5d7aGznsO7KAxNajWofRXbTybqBsueqxMptKelUMdJrOWaC7YULlDGi9Pav2w090Tt 69ZDAnZPWP78clQ4I9AVr8Xq2amg/iLej6kuUWR2P7vtuuW5E1AT9wJO+5N4BurreO0g LnpA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KFzNDPzm; 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 p16si3182545eja.354.2020.04.22.04.02.39; Wed, 22 Apr 2020 04:03:10 -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; dkim=pass header.i=@kernel.org header.s=default header.b=KFzNDPzm; 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 S1729471AbgDVK7h (ORCPT + 99 others); Wed, 22 Apr 2020 06:59:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:51850 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727027AbgDVKCk (ORCPT ); Wed, 22 Apr 2020 06:02:40 -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 AC51D20735; Wed, 22 Apr 2020 10:02:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1587549759; bh=GcAE4oqZ2ODrSfFV7mylhtISMytDHpp8Hp6eMeh9De8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KFzNDPzmA4iecGIK9Ibn879KJg80BjovG4jHD6vczWpFiHAYlYV2so9nU/Fn2Zbdo MKzvs9v5lG0MBPrkPdk6O6WVhi3B3pK14lsFUbijd5otdSdR2GOr3kMsc+8twSE4Xl qsYgX8DBEKaQ0SJ5uUTrGVm2GyWXcwTMDPELpG4I= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Stephen Rothwell , Laurentiu Tudor , Michael Ellerman Subject: [PATCH 4.4 094/100] tty: evh_bytechan: Fix out of bounds accesses Date: Wed, 22 Apr 2020 11:57:04 +0200 Message-Id: <20200422095039.851316602@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200422095022.476101261@linuxfoundation.org> References: <20200422095022.476101261@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: Stephen Rothwell commit 3670664b5da555a2a481449b3baafff113b0ac35 upstream. ev_byte_channel_send() assumes that its third argument is a 16 byte array. Some places where it is called it may not be (or we can't easily tell if it is). Newer compilers have started producing warnings about this, so make sure we actually pass a 16 byte array. There may be more elegant solutions to this, but the driver is quite old and hasn't been updated in many years. The warnings (from a powerpc allyesconfig build) are: In file included from include/linux/byteorder/big_endian.h:5, from arch/powerpc/include/uapi/asm/byteorder.h:14, from include/asm-generic/bitops/le.h:6, from arch/powerpc/include/asm/bitops.h:250, from include/linux/bitops.h:29, from include/linux/kernel.h:12, from include/asm-generic/bug.h:19, from arch/powerpc/include/asm/bug.h:109, from include/linux/bug.h:5, from include/linux/mmdebug.h:5, from include/linux/gfp.h:5, from include/linux/slab.h:15, from drivers/tty/ehv_bytechan.c:24: drivers/tty/ehv_bytechan.c: In function ‘ehv_bc_udbg_putc’: arch/powerpc/include/asm/epapr_hcalls.h:298:20: warning: array subscript 1 is outside array bounds of ‘const char[1]’ [-Warray-bounds] 298 | r6 = be32_to_cpu(p[1]); include/uapi/linux/byteorder/big_endian.h:40:51: note: in definition of macro ‘__be32_to_cpu’ 40 | #define __be32_to_cpu(x) ((__force __u32)(__be32)(x)) | ^ arch/powerpc/include/asm/epapr_hcalls.h:298:7: note: in expansion of macro ‘be32_to_cpu’ 298 | r6 = be32_to_cpu(p[1]); | ^~~~~~~~~~~ drivers/tty/ehv_bytechan.c:166:13: note: while referencing ‘data’ 166 | static void ehv_bc_udbg_putc(char c) | ^~~~~~~~~~~~~~~~ Fixes: dcd83aaff1c8 ("tty/powerpc: introduce the ePAPR embedded hypervisor byte channel driver") Signed-off-by: Stephen Rothwell Tested-by: Laurentiu Tudor [mpe: Trim warnings from change log] Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20200109183912.5fcb52aa@canb.auug.org.au Signed-off-by: Greg Kroah-Hartman --- drivers/tty/ehv_bytechan.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) --- a/drivers/tty/ehv_bytechan.c +++ b/drivers/tty/ehv_bytechan.c @@ -140,6 +140,21 @@ static int find_console_handle(void) return 1; } +static unsigned int local_ev_byte_channel_send(unsigned int handle, + unsigned int *count, + const char *p) +{ + char buffer[EV_BYTE_CHANNEL_MAX_BYTES]; + unsigned int c = *count; + + if (c < sizeof(buffer)) { + memcpy(buffer, p, c); + memset(&buffer[c], 0, sizeof(buffer) - c); + p = buffer; + } + return ev_byte_channel_send(handle, count, p); +} + /*************************** EARLY CONSOLE DRIVER ***************************/ #ifdef CONFIG_PPC_EARLY_DEBUG_EHV_BC @@ -158,7 +173,7 @@ static void byte_channel_spin_send(const do { count = 1; - ret = ev_byte_channel_send(CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE, + ret = local_ev_byte_channel_send(CONFIG_PPC_EARLY_DEBUG_EHV_BC_HANDLE, &count, &data); } while (ret == EV_EAGAIN); } @@ -225,7 +240,7 @@ static int ehv_bc_console_byte_channel_s while (count) { len = min_t(unsigned int, count, EV_BYTE_CHANNEL_MAX_BYTES); do { - ret = ev_byte_channel_send(handle, &len, s); + ret = local_ev_byte_channel_send(handle, &len, s); } while (ret == EV_EAGAIN); count -= len; s += len; @@ -405,7 +420,7 @@ static void ehv_bc_tx_dequeue(struct ehv CIRC_CNT_TO_END(bc->head, bc->tail, BUF_SIZE), EV_BYTE_CHANNEL_MAX_BYTES); - ret = ev_byte_channel_send(bc->handle, &len, bc->buf + bc->tail); + ret = local_ev_byte_channel_send(bc->handle, &len, bc->buf + bc->tail); /* 'len' is valid only if the return code is 0 or EV_EAGAIN */ if (!ret || (ret == EV_EAGAIN))