Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp866146pxb; Wed, 6 Apr 2022 02:32:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRFFUGfXv9XdDzTjQ0EjLPfcH9bfWQQZhHdR62B/tcFgYigaMmlgXWq4qRE4Fa+aE2ACC4 X-Received: by 2002:a17:902:e5ca:b0:156:762b:e48f with SMTP id u10-20020a170902e5ca00b00156762be48fmr7540526plf.140.1649237545628; Wed, 06 Apr 2022 02:32:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649237545; cv=none; d=google.com; s=arc-20160816; b=KXZOTtizvf0b4uHXMe5NlW/QxArYiaqyT2ZWNpiW2XY7xUIhyYvYJY3crmP3xNeVuz cjjmldvlqHulzhAOcKiO7vwbKPWLBoRvOmnwV/ZrUPaIu1gDbZMwg4r0Vx5X7MJwr8Oo 4+GxMLHFZmOKEZnA2awcbMlgmtDA//3dwLgC93orAgm+MWH53NVuPDOni23YSizK6Nvf K5IoTYTMwz9tpsbgtsNfv26o9lbIi6ypuNzTL6Ja+OCZzBVlTNgRKVrLleQxVyOo1oo2 m44MUts9wPPy/LvQs6ZJVDoox1bGt/ms5nXd+jgwq406BiIeOy/U1GYHvlL/NtP3sAX3 P6pw== 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=FA0fcmVbGZ/trCxt2qY53cK4ijTvkx1bMTEXsqxI5eE=; b=asyx9Z2An7mO/vDKwkONhnW2CcKNEXwmXcK1oPZOpghrDZFUlP6CyrPQ3xkrJuzveb agrifp+Q/CP7JUhLVzMcm407kzIfVdj0Okp0DZZzKhb/YUPbsrMzuwbGtHdTDHC9kk0B abEq+G2K00vo2oTZVBltsXgOD3MktnhsbeFpYZR6WO4ZHKgJWBa9B0eRFO1f3S39L8Xo agxJNqXTq3U9m1TF0wO8F1hTvX/Jmmoq/b5V4X9+ah5kBptMyGADvzFIpd2pqb1uvMP5 4u0Db+EiNZviIvfroj1OA2pDL8v1RwyF7eyCMq7pVeEODuGMKizo93mdEdwukPD4sHsa /wjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QHnHRbrn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id c24-20020a17090aa61800b001bf7513fb01si4025617pjq.98.2022.04.06.02.32.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 02:32:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=QHnHRbrn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 23E5E18D98C; Wed, 6 Apr 2022 01:03:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376883AbiDEUgf (ORCPT + 99 others); Tue, 5 Apr 2022 16:36:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352446AbiDEKEf (ORCPT ); Tue, 5 Apr 2022 06:04:35 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C1834A3F6; Tue, 5 Apr 2022 02:53:17 -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 0E1CAB818F6; Tue, 5 Apr 2022 09:53:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6818DC385A1; Tue, 5 Apr 2022 09:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649152394; bh=yD6j1fnTv8REaI/DYQ4/I9JyKfmStY72PLy1+LTQ6pg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QHnHRbrnPJ//FLPj0CrPgDiOc7L+yEt/g/yxGu79yvOzjJ93XwhmD2gXbsVoGF+xr TkFsQICyT6pUCh8QYKf8QvBggqzhioEaHVfdNaOqZBLV07egE95WqlzHVLLoFdnbiL 60RQPrM039CxkEsTvJYOgTCRypRtQSSjZxa8jRvU= 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 5.15 761/913] video: fbdev: sm712fb: Fix crash in smtcfb_write() Date: Tue, 5 Apr 2022 09:30:23 +0200 Message-Id: <20220405070402.643949346@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=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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(-) --- a/drivers/video/fbdev/sm712fb.c +++ b/drivers/video/fbdev/sm712fb.c @@ -1119,7 +1119,7 @@ static ssize_t smtcfb_write(struct fb_in 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_in 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;