Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp3790964ybi; Mon, 29 Jul 2019 12:41:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxo9KZ54K088Ys3QH75s/cnP4eH4qWmwas6AaEuSSbyT9bsqcfMPiO5DhW792+Ds3JKANTc X-Received: by 2002:a17:902:b702:: with SMTP id d2mr115236933pls.259.1564429285116; Mon, 29 Jul 2019 12:41:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564429285; cv=none; d=google.com; s=arc-20160816; b=ctcy//3wTPrKS/xwqOT/ohln3jYnOKfFizBAMsopaGTrx1D6/GM785wVogNh/L/VoG UpRtXTcUuILxIkM9NWzY2GgEfDnEQ1HHVW47ZxDfv4AbP4jOewUpZ+0EeVwb81bloSdn miHgpuzOBK2CKuDzVQMjNHJ8oaXW3MD57vuRiJhwewjKopoFqubGeFgg1d/8JAzGnj8C kokpfNVe2HGmghrv5rOOdXt7JfxBZihDGXCHRT50tmn+cjC2PZZkNQi3v6UU5b2/ry2t jfb9A1aYN2Sr2vzHp2RhEIDXBAdkFht+E1p2jGwudfwoEaAbb2A4UEti6yEo3GahikB1 MxHw== 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=N3LpQFtOGKQsFsfeAyGyQ0oI4aBX46aLkV7hMLxGcDqf4+fvi32KwpztzZwmZmvD83 6yyAKVV9HDFztLNpE9CGGWRlXgcbLkwbUfCQQZV4nCxZSymGVqfU/G7DNyH95L8rnCid VHhTOfH/gM22flRMfDQSbRlPTWmRnVJqtBCwMdg2fv9jKTDQ+NOku+lxsvxKQ7BgKlYv FPkzD03nvpJhhCBHZRHDLY5L6wqLp+FRH/AfPFU/GgOMcEsoc9ytd9X779OT5S9u122J 06T8qUpuEkQlZCLnSL8Ra+OmjEOcSxHiOj1fO7ALH5hM22lTJdtKPmJwVtBysDOblN9G 2dhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=QYrRAU1y; 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 e5si11392768pgl.536.2019.07.29.12.41.10; Mon, 29 Jul 2019 12:41:25 -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=QYrRAU1y; 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 S2388893AbfG2Tik (ORCPT + 99 others); Mon, 29 Jul 2019 15:38:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:53524 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388559AbfG2Tid (ORCPT ); Mon, 29 Jul 2019 15:38:33 -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 BE5A720C01; Mon, 29 Jul 2019 19:38:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1564429112; bh=HRmdymFz9CoKWHbTLjLYlSb8GYeHY4UE37+eJqbgQPE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QYrRAU1y8pOxOOlIr+Vu6NFMKm20CjQDPOOLlMtJ4+b+tT6A7kHsCpHn76u6Dqk9J nNTdH8R4dMQRjmGCfK33ak2Bb2nnuYlwGMTEKAooSCvAYSP7HV0W8aOIOWQZfrCN6U B/bygsyfHK5lXzEKj1wfp5uOdLFSNJb5UQjk6QMU= 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.14 288/293] hpet: Fix division by zero in hpet_time_div() Date: Mon, 29 Jul 2019 21:22:59 +0200 Message-Id: <20190729190846.309781280@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190729190820.321094988@linuxfoundation.org> References: <20190729190820.321094988@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