Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp689258pxb; Tue, 5 Apr 2022 18:53:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwo8eWCF+mKSwtG4J+/Q8xgQyFhaA+p1kNNERFZtXDzUcYMKFMDTUooMKmvKWy12fVdRl5C X-Received: by 2002:a17:90b:3b8f:b0:1c7:b62e:8e87 with SMTP id pc15-20020a17090b3b8f00b001c7b62e8e87mr7287948pjb.156.1649210030417; Tue, 05 Apr 2022 18:53:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649210030; cv=none; d=google.com; s=arc-20160816; b=pirrdAN/Fz0uRFJ9/2MgwkElt8CGCIeXBrdWAFo6iQvGESKeNTPuZbPFXGzD7XkUmn xcUEzc1uNPQWqQKaQGE7/Jy+wKwLR0yW8sdfumRfZrhpSNAEX8QATixH8TzqFoYw9my2 4X0tVJu9DYeTIOPDZvZYH6BJROsW4G+b3N+51WXsFJP9KVvC3RKAN0lZDcAvJhdWoK9z VOS+EMg+SKKjN4JHT3JaJk8im6YJI3B/nd2FQHc87s3uAj5MuDMkRSOLqxJoNgckziek +FydMjT5XT+p0hmlMTX2yMayijAO7nTjl0sMCyMWy+TtXIgHMDaoxoh7F6rM02yJfb+9 KuKg== 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=A85iVk2CFt7E881WdPeGYNaK6bt/bJoHGVE6+A5UH67a0todS8V41F16mHv4QRdWfG c3PSCNi9wuEcXzlZVMO9WqUnkSPM/6GXwD9jj5HCJb552fYUuhvYuCE+FCL1qyLTb4C+ 7sZ1Kx4a2ktrZeLG1oMJe9SrZxoYtSMv4iBrLi4y2di13cs4Gh2L0QVuvTcsK8n+TCB0 Gdu8/aAtGJQbF87jd6zJMrt1d9mV7WPqMwgQ8rE+eIBD7tmcFAs3U1rAadeCVvSROr7m 4EX0kHYuxwP+loETBZzZMdgTFmFpNcxfPcgvE8m0cBNqyP65MFI1+M8//33wMffMmISn draw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dw97mN+X; 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 u62-20020a638541000000b00381ee9a9730si14595596pgd.407.2022.04.05.18.53.27; Tue, 05 Apr 2022 18:53:50 -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=dw97mN+X; 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 S1388529AbiDEOkL (ORCPT + 99 others); Tue, 5 Apr 2022 10:40:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243545AbiDEJj5 (ORCPT ); Tue, 5 Apr 2022 05:39:57 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9042AA023; Tue, 5 Apr 2022 02:24:45 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 07C2261368; Tue, 5 Apr 2022 09:24:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 15125C385A2; Tue, 5 Apr 2022 09:24:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649150684; bh=Cw2NlYAm/sub3uTEA3b2qIyrR3JDeMkKrC26amsoKtQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dw97mN+XBE0GBNuUjBXZuXy5SF5MP3/CL3SGpZb1n4n+mJvPV8QaXAh3+TjiONuP/ P+D7pFBkIJAEzLk9MPNd/5qVt16In5aCcCCgXI9WS+kkn6zUS2V+80S77QQ1q+39uV K/u6jpRbUHdEmDfn4CHe2EqWWTrKXilsvbJPOhAk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zheyu Ma , Helge Deller Subject: [PATCH 5.15 143/913] video: fbdev: sm712fb: Fix crash in smtcfb_read() Date: Tue, 5 Apr 2022 09:20:05 +0200 Message-Id: <20220405070344.120491507@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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.1 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;