Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp4329948pxb; Wed, 20 Apr 2022 00:19:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQhI5phI4C017YtT0F7BruR9MHFWLpLrhWCyc8k7Ybo3WhKWdLIqfTERI0xEtnlkJCLQJr X-Received: by 2002:a05:6a00:1489:b0:50a:90d7:e69d with SMTP id v9-20020a056a00148900b0050a90d7e69dmr9445579pfu.70.1650439143963; Wed, 20 Apr 2022 00:19:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650439143; cv=none; d=google.com; s=arc-20160816; b=05tfwvN8S3DXc2ytUgJPpWz8bWythJ48FKozJF8E0YxCaPz+FRt8onFLFIg9jLqgEL eXJH+REaAB9RI0pgeQjDEScA4WmfBn+BL4BfAI7UubmAEVxr4y24vpKvaGA3vcGVFENn nbZQyQ6k+PkS3pHgBqXfWpaCT+yoTL7jekQSDoTTD3TBzVUu6SYyWv4oEvFB7NEVJ1k/ LAVFk7y5yyy4791gT5XTc8A4jntR1yvTwgG/i/BotCRKORw453K1ix1PBjBgUVN14GNw FnYdNe52e/pDjKlAVf776mZyQ4YSX5OJgEYMTYOJlTfxr0mblTFd8/330Ab1SnDEFDBm qNNw== 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=sLKmCjVzuyd+rLIF/FcI/6q334eOhyRHQzD1IJYOaSw=; b=pSXJ59R5JcmP/xMD2fAmxFVPcx+EapH8zd9a2ndgZ14UPvZSBXG1uq+2CbeNgkHHvw GhTsYXJjLwlYj/q85y+xiI1UgJ3zf09wXQfSS5p/mvgim4rzB3Fki9PTRk1IpkO3gFNb h0yfqZu+Zz5tMbP5c0ln2R/KawiSdFxZ7rEEO2C0RDiyVRN/ugyM2MI/X1SkPsIM1kD9 1Fa1Aa/n4671cUlzYDY+olLXhcm5NuKCeMeuXsl/N1CmxVaGKjYuG6/zqh+Mx0YJ7iC3 nEGWg/lyN5OaElfAdnXmY4m+VqytvCtXbjR3ZCrf8MLm/33YDBZaxxsDCehhtp/1veq6 xmsA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=slEHDHHM; 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 e11-20020aa7824b000000b004faa8ee4f05si1342381pfn.98.2022.04.20.00.18.49; Wed, 20 Apr 2022 00:19:03 -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=slEHDHHM; 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 S240953AbiDROAq (ORCPT + 99 others); Mon, 18 Apr 2022 10:00:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243254AbiDRNhd (ORCPT ); Mon, 18 Apr 2022 09:37:33 -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 EEA4327B37; Mon, 18 Apr 2022 05:58:20 -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 2DF6B60FD9; Mon, 18 Apr 2022 12:58:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 228C7C385A1; Mon, 18 Apr 2022 12:58:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650286699; bh=twzclvZsHbd4y+Um/gkqCg/aeIM7E1y+GK1Xfh8DT3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=slEHDHHMgvWPv2FS/bYZMWKFfZPmgiMooNcrjmQEir4PiCQfq5DSEiXZ1fDJ0YsNZ 0nab7KkU6UICCe+Zs/OEa3it7AT6R6WOB6kemvR4MBgSDYO93f8h+KDHGKk9ZjwL3S iOH7C+mCvRWr6zSf8p2sQjoo1LR/7S3BL/MQNH2w= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zheyu Ma , Helge Deller , Sasha Levin Subject: [PATCH 4.14 177/284] video: fbdev: sm712fb: Fix crash in smtcfb_write() Date: Mon, 18 Apr 2022 14:12:38 +0200 Message-Id: <20220418121216.772667495@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: Zheyu Ma [ Upstream commit 4f01d09b2bbfbcb47b3eb305560a7f4857a32260 ] When the sm712fb driver writes three bytes to the framebuffer, the driver will crash: BUG: unable to handle page fault for address: ffffc90001ffffff RIP: 0010:smtcfb_write+0x454/0x5b0 Call Trace: vfs_write+0x291/0xd60 ? do_sys_openat2+0x27d/0x350 ? __fget_light+0x54/0x340 ksys_write+0xce/0x190 do_syscall_64+0x43/0x90 entry_SYSCALL_64_after_hwframe+0x44/0xae Fix it by removing the open-coded endianness fixup-code. Signed-off-by: Zheyu Ma Signed-off-by: Helge Deller Signed-off-by: Sasha Levin --- drivers/video/fbdev/sm712fb.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/drivers/video/fbdev/sm712fb.c b/drivers/video/fbdev/sm712fb.c index 0d80ee9766a6..f4396d1389e4 100644 --- a/drivers/video/fbdev/sm712fb.c +++ b/drivers/video/fbdev/sm712fb.c @@ -1119,7 +1119,7 @@ static ssize_t smtcfb_write(struct fb_info *info, const char __user *buf, count = total_size - p; } - buffer = kmalloc((count > PAGE_SIZE) ? PAGE_SIZE : count, GFP_KERNEL); + buffer = kmalloc(PAGE_SIZE, GFP_KERNEL); if (!buffer) return -ENOMEM; @@ -1137,24 +1137,11 @@ static ssize_t smtcfb_write(struct fb_info *info, const char __user *buf, break; } - for (i = c >> 2; i--;) { - fb_writel(big_swap(*src), dst++); + for (i = (c + 3) >> 2; i--;) { + fb_writel(big_swap(*src), dst); + dst++; src++; } - if (c & 3) { - u8 *src8 = (u8 *)src; - u8 __iomem *dst8 = (u8 __iomem *)dst; - - for (i = c & 3; i--;) { - if (i & 1) { - fb_writeb(*src8++, ++dst8); - } else { - fb_writeb(*src8++, --dst8); - dst8 += 2; - } - } - dst = (u32 __iomem *)dst8; - } *ppos += c; buf += c; -- 2.34.1