Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp693294pxb; Tue, 5 Apr 2022 19:03:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw0j2ggh9aRjsNxGlDlx1oWga+SCRyHHvX0ULa23uo9fu+PMUDLCW1CLywokZbsx0d0c+3o X-Received: by 2002:a05:6a00:1a06:b0:4fc:d6c5:f3d7 with SMTP id g6-20020a056a001a0600b004fcd6c5f3d7mr6650716pfv.53.1649210587126; Tue, 05 Apr 2022 19:03:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649210587; cv=none; d=google.com; s=arc-20160816; b=tQ/YchU8qBocX6vYkCsWpshbyojcslLEtzO9t73uObSJ9eqzJNTRGxPH6I6Q0GqqwP 4jzIKzfwe2sXdLU+kzbMwtdckvU3w+I5JZ7b4tRoJk3ssEcAbewH9JZDuH0hRG/z3b8l Bmp0cBTiYHoiL1b+k0nLVu8G/KupIg5pVUiQgeCv4FUJD2H4mRsnBFJdYK8f775Ud8SL /7/WZ61s2v6QODyVUsO01AhMxpT3HwW40JIPevDw+hoeHXfEaiy2J4RiVIIKvV8EQdaN w6IkdEHlDmCiggndtsiwokwv/tkScbmEqlSKQ+vZQfUDw7ey7PPR2VUkJfEHOmdJO7ti yWIA== 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=smLJzgz6fL5pqSPl62vcbINGl7LuxqpsOlarvt0mcXR5591o3hsDP3HT5macqSeOgd lUWrCvZk/OAZyrINUbniRvGLebJdvPpDG333C3IFfjzFAX6EcAEsnqQVhIm1Wgcyi8QB IYnOQBornoUdr1kYNdaOeC9Fm7HDWtz15VWNK4eOEZYWFuaekPAFW6yaVCT7ZiVIWJi1 AajL0Agiw5XTGicz4FTJ9pi3Z6JDWu3tlkW0O2uygWUjl8cLoXvUk5rwHDpk11lrql6c vbxHeHa7HKgO9PbKiP5C1oLo2ZqlyrFdQQCYSBPm/XcM3gAjYuitV01xfe6a6vkQdpdR FO7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XFmGhhY8; 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 n9-20020a17090a928900b001caa86392easi3335436pjo.70.2022.04.05.19.02.49; Tue, 05 Apr 2022 19:03:07 -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=XFmGhhY8; 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 S1347066AbiDEN2G (ORCPT + 99 others); Tue, 5 Apr 2022 09:28:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345242AbiDEJWX (ORCPT ); Tue, 5 Apr 2022 05:22:23 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83E043586D; Tue, 5 Apr 2022 02:09:54 -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 EC616614FC; Tue, 5 Apr 2022 09:09:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CD7BC385A2; Tue, 5 Apr 2022 09:09:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149793; bh=yD6j1fnTv8REaI/DYQ4/I9JyKfmStY72PLy1+LTQ6pg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XFmGhhY8wqGjxThk7JtdVHcIzd96xQvn+ZCTIR+K04VlqLAda4DOjXYwvq5NQ0Ex3 gL1L7vlOIGzqIpsgZVvbvqw78ATWBpcA/mAs3prfGyC7EPM9KwlTYsQlVdkAEuoqGi ZwtWMEEAL5nUnbxcXUq1DbE3IibU1o98gmHmTJUk= 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.16 0844/1017] video: fbdev: sm712fb: Fix crash in smtcfb_write() Date: Tue, 5 Apr 2022 09:29:17 +0200 Message-Id: <20220405070419.293220424@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@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: 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;