Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp517481pxb; Thu, 9 Sep 2021 06:17:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgIgvewS9E5YhXrk/FF1Encl5mIP4Gu9QlbbAr67Rq+zEOkQleQvR1V7Qx1bdlXzKP/pGn X-Received: by 2002:a05:6e02:1a87:: with SMTP id k7mr2411726ilv.122.1631193436841; Thu, 09 Sep 2021 06:17:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631193436; cv=none; d=google.com; s=arc-20160816; b=zs0l5fimlvkbNEoxp7f9OJQpRUCJjnqBKGBNBHYogeZblSoIc5iAFTPjqc50xma+Vj p+wnAR/jd3JlBH6ejFISRd/PMjOAH2B+1nHLp1LElX7p5xivhypFKYoFlOvdKqi4LG19 pe26LNtBfe9YPOpdBdTT0XfWsJ78FOQ14YnsINFrjiYzIcl7kMgShSXFR6ugLeXemrH5 WHYwP4IapbIu0B2/DV2cn0OZJlNfygXnnKkzLOLXLqaOP4pCHWbvwF3TbRe1tHfJT6Yc AX9qIgOaPjK8+7n8Pit5+56lBUT+XfQI+CwOL8pNgrLWLnarR49W2Bh/PFh91ONxmee4 849Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pynlGbcpZaQUWZGrmHRYdTwAkEhm8X0XQaUt2Ul5HiA=; b=dO2T4fNXaw0VDgKcm9ghfNWNZgeJH6zwy5fQfkbsQPDDk7zhEZeAghsW9Dvh1l6Jnw acOMc/YdvQt0ApOpSKgUGjq4Q8sw2tkoSxoj5FaxMufhsSNSVxDuJB7Ixr5cBtENEPZ4 My2KyiMzXk5mZeGYfkhHN4PepVfw8w7uRGiUTQv+Em7Vtlx5wGvTehQNUg/eJT6ljgeT Q73fJv+9vjnIAAY8c65SK24m1qsJIjI8jDavDT+QxybsV/ja438RZiF3lJuWC/1R1Hay U//yJbOh+bT56v1D2ebbs0Kf4cIGNf2sFl8aqx6O4kjwot3nmlDKYl66j6kHaCbyAoNa 4EPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YsWunhR5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c18si1984360iod.38.2021.09.09.06.17.00; Thu, 09 Sep 2021 06:17:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YsWunhR5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359343AbhIINRB (ORCPT + 99 others); Thu, 9 Sep 2021 09:17:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:46260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357493AbhIINBD (ORCPT ); Thu, 9 Sep 2021 09:01:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 9E15263284; Thu, 9 Sep 2021 11:59:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631188765; bh=oCuclDFQR/TWrSxh1Tg1IKmN6apKshahn0yGbqtvOmY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YsWunhR5W130LKU/tyBMEMuqLABBvsfS3dPmSpwXElSorGgQTyP//YUZpMi64m1q+ djUCAUXMW+Rgp0qwzfHfMBGVfFJiX7/m5IHcpVch8uSloNS5QrwA8AM19SfLKuZfTV hFqaDWMnsIRWOaRUzoiYVq84/opNYoLoMnjECey3vRHzhSeIffkltXjri3fcZEXcS3 FVni/+Y5YCSGfn+oxEEaiAFyHgmHkWI5tAS5EgIWAzT9IME0yPGoYXHD+DgDAcPE1K DsgzDsESpgNqhbZ69hYmzjsp4X1BvCAIg31R34jtvCZ48Xuwh/JRGytb2jgOFDDJSH GHMITWjWTQQHQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Zheyu Ma , Sam Ravnborg , Sasha Levin , linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 4.14 19/59] video: fbdev: riva: Error out if 'pixclock' equals zero Date: Thu, 9 Sep 2021 07:58:20 -0400 Message-Id: <20210909115900.149795-19-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210909115900.149795-1-sashal@kernel.org> References: <20210909115900.149795-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zheyu Ma [ Upstream commit f92763cb0feba247e0939ed137b495601fd072a5 ] The userspace program could pass any values to the driver through ioctl() interface. If the driver doesn't check the value of 'pixclock', it may cause divide error. Fix this by checking whether 'pixclock' is zero first. The following log reveals it: [ 33.396850] divide error: 0000 [#1] PREEMPT SMP KASAN PTI [ 33.396864] CPU: 5 PID: 11754 Comm: i740 Not tainted 5.14.0-rc2-00513-gac532c9bbcfb-dirty #222 [ 33.396883] RIP: 0010:riva_load_video_mode+0x417/0xf70 [ 33.396969] Call Trace: [ 33.396973] ? debug_smp_processor_id+0x1c/0x20 [ 33.396984] ? tick_nohz_tick_stopped+0x1a/0x90 [ 33.396996] ? rivafb_copyarea+0x3c0/0x3c0 [ 33.397003] ? wake_up_klogd.part.0+0x99/0xd0 [ 33.397014] ? vprintk_emit+0x110/0x4b0 [ 33.397024] ? vprintk_default+0x26/0x30 [ 33.397033] ? vprintk+0x9c/0x1f0 [ 33.397041] ? printk+0xba/0xed [ 33.397054] ? record_print_text.cold+0x16/0x16 [ 33.397063] ? __kasan_check_read+0x11/0x20 [ 33.397074] ? profile_tick+0xc0/0x100 [ 33.397084] ? __sanitizer_cov_trace_const_cmp4+0x24/0x80 [ 33.397094] ? riva_set_rop_solid+0x2a0/0x2a0 [ 33.397102] rivafb_set_par+0xbe/0x610 [ 33.397111] ? riva_set_rop_solid+0x2a0/0x2a0 [ 33.397119] fb_set_var+0x5bf/0xeb0 [ 33.397127] ? fb_blank+0x1a0/0x1a0 [ 33.397134] ? lock_acquire+0x1ef/0x530 [ 33.397143] ? lock_release+0x810/0x810 [ 33.397151] ? lock_is_held_type+0x100/0x140 [ 33.397159] ? ___might_sleep+0x1ee/0x2d0 [ 33.397170] ? __mutex_lock+0x620/0x1190 [ 33.397180] ? trace_hardirqs_on+0x6a/0x1c0 [ 33.397190] do_fb_ioctl+0x31e/0x700 Signed-off-by: Zheyu Ma Signed-off-by: Sam Ravnborg Link: https://patchwork.freedesktop.org/patch/msgid/1627293835-17441-4-git-send-email-zheyuma97@gmail.com Signed-off-by: Sasha Levin --- drivers/video/fbdev/riva/fbdev.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/video/fbdev/riva/fbdev.c b/drivers/video/fbdev/riva/fbdev.c index 1ea78bb911fb..c080d14f9d2a 100644 --- a/drivers/video/fbdev/riva/fbdev.c +++ b/drivers/video/fbdev/riva/fbdev.c @@ -1088,6 +1088,9 @@ static int rivafb_check_var(struct fb_var_screeninfo *var, struct fb_info *info) int mode_valid = 0; NVTRACE_ENTER(); + if (!var->pixclock) + return -EINVAL; + switch (var->bits_per_pixel) { case 1 ... 8: var->red.offset = var->green.offset = var->blue.offset = 0; -- 2.30.2