Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3804389ybi; Mon, 29 Jul 2019 12:58:43 -0700 (PDT) X-Google-Smtp-Source: APXvYqwVNGotKc2mHwBs3JWz9nx+gcKIDGMqDVxv/ueAktZ0Qv9QBo+HYmqOig/Aoce7Fao/0Lyd X-Received: by 2002:a17:902:b608:: with SMTP id b8mr113358175pls.303.1564430323833; Mon, 29 Jul 2019 12:58:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564430323; cv=none; d=google.com; s=arc-20160816; b=ecZFzO8+N866stbcIIYrfzPqHKlIRwZ53D+Sb9F68x/31hLPjM1QGfqYyfzWY6frxW 9HZh3PStLy8CtdyBzHm+eiUC/tViqzotgeeanhrGVfA+vmuyMQkrlDYk3/QAaElRjyV8 YK0mYPJHd8RBX6pqZiSQzaq8w5iBwL3h1+CLlYjCJvUWH4Xov7Me8MDjYGHKl0yhB7Zn TdjNXsTzwL9D6KSwcG8xcufijc3cpCanrcdY7fFTaaFXYwqE4PEkIw2K7h5L/u79D38s 2aX6n7vzNQa4ylnHYXBvFffRQkO5K/V2c3sc5TelOuRJumQaLjIkI101/nWX577z1+DR zCQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=aj8+j5REw7/gfuGdnTIygF0gbiywhe8iuo/iVCZhV5E=; b=bsIQOpPjmMxaag0upVr7A1rX133SmstvgKIcWv0v7yPExrtxW8zWFhEDa17U2C7i/D t6H/qPHvjrHUwiUrEiWrh2YQdkyx6jvrcR8h45Fm1V5XoIqZTgrbuTh56gI2T8JlGi3f avT8Jfa9axgI/6GpKGvY7zQh7oS6l/v1QfW1fBkiIBGvEIsvqwHnMwmcKmXZzIkMquQw aPRRu57Rhpb9w6kO+ZByxp2H/4s/8ntINuoGIaRzAEx4ZpycDdScnXiwaWoNBCr5ofMM 4tGYpl8sTsLIFPaEPuY4Ee6byM/mZTwEg0/oYFeDO1yQua7pNFa8100dFGWlcrmwg0zB 9JzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EQrC3iEt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m11si25924188pls.148.2019.07.29.12.58.28; Mon, 29 Jul 2019 12:58:43 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EQrC3iEt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2404097AbfG2Tyn (ORCPT + 99 others); Mon, 29 Jul 2019 15:54:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:47358 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2404053AbfG2Tyl (ORCPT ); Mon, 29 Jul 2019 15:54:41 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id AEB602171F; Mon, 29 Jul 2019 19:54:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564430080; bh=B/oxvIEJXcPzHXdB0xrK2ROxMA5FbIFbDsHay0+/Qgw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EQrC3iEt2b/TmPV6aSYrGP6JoLh6yF0Vu+qomMVX3BgoPwzlop+BDfDV+Byh6TYWA qOTVzSZ6tdtRVlyIfUyimCdaX7JWFW7gF7zFBuVvKUPi5SR5bmp1DimIloMTq/c3l4 js4vM871+HPuT1spW+xeUdS+4/we6vn7BGq3o7vg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Kefeng Wang , Zhang HongJun , Arnd Bergmann Subject: [PATCH 5.2 189/215] hpet: Fix division by zero in hpet_time_div() Date: Mon, 29 Jul 2019 21:23:05 +0200 Message-Id: <20190729190812.807982759@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190739.971253303@linuxfoundation.org> References: <20190729190739.971253303@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Kefeng Wang commit 0c7d37f4d9b8446956e97b7c5e61173cdb7c8522 upstream. The base value in do_div() called by hpet_time_div() is truncated from unsigned long to uint32_t, resulting in a divide-by-zero exception. UBSAN: Undefined behaviour in ../drivers/char/hpet.c:572:2 division by zero CPU: 1 PID: 23682 Comm: syz-executor.3 Not tainted 4.4.184.x86_64+ #4 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Ubuntu-1.8.2-1ubuntu1 04/01/2014 0000000000000000 b573382df1853d00 ffff8800a3287b98 ffffffff81ad7561 ffff8800a3287c00 ffffffff838b35b0 ffffffff838b3860 ffff8800a3287c20 0000000000000000 ffff8800a3287bb0 ffffffff81b8f25e ffffffff838b35a0 Call Trace: [] __dump_stack lib/dump_stack.c:15 [inline] [] dump_stack+0xc1/0x120 lib/dump_stack.c:51 [] ubsan_epilogue+0x12/0x8d lib/ubsan.c:166 [] __ubsan_handle_divrem_overflow+0x282/0x2c8 lib/ubsan.c:262 [] hpet_time_div drivers/char/hpet.c:572 [inline] [] hpet_ioctl_common drivers/char/hpet.c:663 [inline] [] hpet_ioctl_common.cold+0xa8/0xad drivers/char/hpet.c:577 [] hpet_ioctl+0xc6/0x180 drivers/char/hpet.c:676 [] vfs_ioctl fs/ioctl.c:43 [inline] [] file_ioctl fs/ioctl.c:470 [inline] [] do_vfs_ioctl+0x6e0/0xf70 fs/ioctl.c:605 [] SYSC_ioctl fs/ioctl.c:622 [inline] [] SyS_ioctl+0x94/0xc0 fs/ioctl.c:613 [] tracesys_phase2+0x90/0x95 The main C reproducer autogenerated by syzkaller, syscall(__NR_mmap, 0x20000000, 0x1000000, 3, 0x32, -1, 0); memcpy((void*)0x20000100, "/dev/hpet\000", 10); syscall(__NR_openat, 0xffffffffffffff9c, 0x20000100, 0, 0); syscall(__NR_ioctl, r[0], 0x40086806, 0x40000000000000); Fix it by using div64_ul(). Signed-off-by: Kefeng Wang Signed-off-by: Zhang HongJun Cc: stable Reviewed-by: Arnd Bergmann Link: https://lore.kernel.org/r/20190711132757.130092-1-wangkefeng.wang@huawei.com Signed-off-by: Greg Kroah-Hartman --- drivers/char/hpet.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) --- a/drivers/char/hpet.c +++ b/drivers/char/hpet.c @@ -567,8 +567,7 @@ static inline unsigned long hpet_time_di unsigned long long m; m = hpets->hp_tick_freq + (dis >> 1); - do_div(m, dis); - return (unsigned long)m; + return div64_ul(m, dis); } static int