Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4082661ybi; Mon, 29 Jul 2019 18:53:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqz17yGayS3djEXa9PnOOxwWx/qQvvxhU2Sr9L5OqopbsqgGfs2q8KpTKr2N0RQ1xvrBxiQA X-Received: by 2002:a62:ac1a:: with SMTP id v26mr40213978pfe.184.1564451594966; Mon, 29 Jul 2019 18:53:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564451594; cv=none; d=google.com; s=arc-20160816; b=hNndr0n3YAL2O57aWCH6axOTpu47CPPSIuR/2Gy1rGYqM4Gy4xHWsWdKnxYHZh/uHD sUK1BTMr/tATYfbf4sWILGWdOOrb/7QsVULBXvg8NEycdWjxSXpK357mHVui1720jyew 5RkYfJEHi5ExF/6i5I4dwY5wA3vbtW9echt4UIrYCWSB6ddAgw5HvQjZi4Dq7IPmdszJ 3APF4kPboCWE7Bux5PUZtxmM2txI/g9O6/bewvEH9zYd41uVozcx76ToOkf5V+0LmoMP 0+onlVE7oO8YjgTsjsCgYmNQBb19M0QkiGxhX774sxmM+cV6l9S3eokY6gw6yGn0r83w zvTQ== 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=a3POnc4DIFJG8l2P0vBJ0NTssUEStvxtYGGqyCXclv4=; b=w653bzqTUGXwXW7l76TLiXjPvJd/A7uflraDzBhJmy5R230np+9hL9l+LsUCdmf+j1 vzK46yUmrVRiSTC3WCtuuafRvcLV35DzDtma00Q21gf60uy5gF2Tv1T0GKxqvfrVRlL/ sYcT87HfS+gnOXiwEIN0yJTjm8VPA+FhbyhU42Ia7t8+7NIG3HMRBe73n7mehxAz0Ttm yLCPAEVN3lZ+DMSy3pCNOGF/J+KqzTcFkZ0GGZBtdSKNwRswIhFu65AnsFBiKQQ1+w/r 0RPB+CVLAVLJ0MbwADNBYlas4yf/azKvM4+CrYCK1qINu3jVeI+xBX9/9W/7DsoJf4wQ MGOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Ql3Lp4ia; 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 c18si27318086plo.316.2019.07.29.18.53.00; Mon, 29 Jul 2019 18:53:14 -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=Ql3Lp4ia; 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 S2389807AbfG2Tof (ORCPT + 99 others); Mon, 29 Jul 2019 15:44:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:33048 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389513AbfG2To2 (ORCPT ); Mon, 29 Jul 2019 15:44:28 -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 96AC3205F4; Mon, 29 Jul 2019 19:44:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429467; bh=HRmdymFz9CoKWHbTLjLYlSb8GYeHY4UE37+eJqbgQPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ql3Lp4ia9nrohhcXgN/tibefFEdTnfu/xHqNl3xayH0Z78CkMR1Bw2R5hHkJGONSQ 2wAl8esjAmPeXEXSmpZKXainpRvQ3l+Ip2nh9uYja05tPtRRSG3GtpmZtS1p8F08d0 3HxCHalkAN+evzruVwx1uhvDb+0MhQclLAK2AY6U= 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 4.19 106/113] hpet: Fix division by zero in hpet_time_div() Date: Mon, 29 Jul 2019 21:23:13 +0200 Message-Id: <20190729190720.652873366@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190655.455345569@linuxfoundation.org> References: <20190729190655.455345569@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 @@ -570,8 +570,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