Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp2986046pxb; Mon, 18 Apr 2022 12:43:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyMcYBHLMuA0qCbGgB/bBBMm8lamgGD4c2kM00/lMAZ9M04aBqdID4vM78lLPcJijpj5+j9 X-Received: by 2002:a17:90a:898c:b0:1cb:aa19:a352 with SMTP id v12-20020a17090a898c00b001cbaa19a352mr14801828pjn.170.1650311009810; Mon, 18 Apr 2022 12:43:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650311009; cv=none; d=google.com; s=arc-20160816; b=ssAp5ykmJ8L9ysi8/6BwsKIfucwjJuowkdXUV8XObAUU3YxrxIEA0YOcSIEQSf0w// qfinKou/hbQzyhAqRAqfYCTUOAOAOw05eHzMMtqsC06KI7u3vp80YkGguyXM4Hac/FY+ SNo9sGe/zmBI0pvRVMZMNthaMKUAIQykedt0N/PRoKBUDB+tB9clwppUAHygZoL4mPh+ SAcMr7b38kqXKJ2fsC2wLDQTrTbpu/NjD1u7EJjTqrpumJZIt/FtZ1rpxYJu6qwJP16O rs28hI1aRT6R2UtdiRmHrcw4ip8ox2C4523bI1nh2tAQatZfUrYfq3NYPXFijjsekJQ3 pQfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=x4eYxcN4jg/qokdcpVQHX8C7weXlHf/tFvb18+IQAfQ=; b=u4GNi6qJ0Q+J19jg3WbGaWECRwlPQijxwhEfCYr4EUzTMlqHvd2bZQ401hDpw4g/xm BrL5hr1NFKYoupvz2VMsLl6xYTl4Znmum745zFbh1GmtWCw6iHUPzzfob+LdVd/3L9Kz iHHDJuqgZjqQTAuAmiSIynL7PAS0ma5Zj41xBdb4PWvFrWKdMC2VRKfvSxvDLsznevXt EG4uBqCKYRDd2VXUOI/MNTwxuS2jpxa2/H4hIwSq9Q33yMCmWhBxV4n07iRU6iYdmADF 77boUyqbzlgJSIczdEX0jS0WPP3zLkBKtk5xOC3Yk4RbKBH4uf9jSU6ErMra4SPoWVM3 MEtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ts/rh33L"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j64-20020a638043000000b003a9eb7ecffcsi3299277pgd.181.2022.04.18.12.43.13; Mon, 18 Apr 2022 12:43:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="ts/rh33L"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243561AbiDRNiH (ORCPT + 99 others); Mon, 18 Apr 2022 09:38:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243686AbiDRNKX (ORCPT ); Mon, 18 Apr 2022 09:10:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1AE2114C; Mon, 18 Apr 2022 05:49:51 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0A3F8B80E4B; Mon, 18 Apr 2022 12:49:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41891C385A1; Mon, 18 Apr 2022 12:49:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286188; bh=Cw2NlYAm/sub3uTEA3b2qIyrR3JDeMkKrC26amsoKtQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ts/rh33Lvr1y1PinEXLgkc31/cfbM0VOwmScVuMPmhq33fKUupYcUdLpsBN0VURcn U1v7PbTU1kTQxJNhpId0RIx3vt3G/jwSTGnFtzrIJR0NLnXZySxOoFo3PovirdLaKE bJZkx4cs6SyhuirVfvRdnIuO1fTwcCPgMEEXeQH8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zheyu Ma , Helge Deller Subject: [PATCH 4.14 039/284] video: fbdev: sm712fb: Fix crash in smtcfb_read() Date: Mon, 18 Apr 2022 14:10:20 +0200 Message-Id: <20220418121211.806496442@linuxfoundation.org> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20220418121210.689577360@linuxfoundation.org> References: <20220418121210.689577360@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Helge Deller commit bd771cf5c4254511cc4abb88f3dab3bd58bdf8e8 upstream. Zheyu Ma reported this crash in the sm712fb driver when reading three bytes from the framebuffer: BUG: unable to handle page fault for address: ffffc90001ffffff RIP: 0010:smtcfb_read+0x230/0x3e0 Call Trace: vfs_read+0x198/0xa00 ? do_sys_openat2+0x27d/0x350 ? __fget_light+0x54/0x340 ksys_read+0xce/0x190 do_syscall_64+0x43/0x90 Fix it by removing the open-coded endianess fixup-code and by moving the pointer post decrement out the fb_readl() function. Reported-by: Zheyu Ma Signed-off-by: Helge Deller Tested-by: Zheyu Ma Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/video/fbdev/sm712fb.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) --- a/drivers/video/fbdev/sm712fb.c +++ b/drivers/video/fbdev/sm712fb.c @@ -1047,7 +1047,7 @@ static ssize_t smtcfb_read(struct fb_inf if (count + p > total_size) count = total_size - p; - buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, GFP_KERNEL); + buffer = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!buffer) return -ENOMEM; @@ -1059,25 +1059,14 @@ static ssize_t smtcfb_read(struct fb_inf while (count) { c = (count > PAGE_SIZE) ? PAGE_SIZE : count; dst = buffer; - for (i = c >> 2; i--;) { - *dst = fb_readl(src++); - *dst = big_swap(*dst); + for (i = (c + 3) >> 2; i--;) { + u32 val; + + val = fb_readl(src); + *dst = big_swap(val); + src++; dst++; } - if (c & 3) { - u8 *dst8 = (u8 *)dst; - u8 __iomem *src8 = (u8 __iomem *)src; - - for (i = c & 3; i--;) { - if (i & 1) { - *dst8++ = fb_readb(++src8); - } else { - *dst8++ = fb_readb(--src8); - src8 += 2; - } - } - src = (u32 __iomem *)src8; - } if (copy_to_user(buf, buffer, c)) { err = -EFAULT;