From owner-freebsd-current@freebsd.org Tue Feb 28 23:02:22 2017 Return-Path: Delivered-To: freebsd-current@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 0860CCF2A71 for ; Tue, 28 Feb 2017 23:02:22 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: from mail-wr0-f182.google.com (mail-wr0-f182.google.com [209.85.128.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9D562A19; Tue, 28 Feb 2017 23:02:21 +0000 (UTC) (envelope-from cse.cem@gmail.com) Received: by mail-wr0-f182.google.com with SMTP id u108so18722735wrb.3; Tue, 28 Feb 2017 15:02:21 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:reply-to:in-reply-to:references :from:date:message-id:subject:to:cc; bh=0ZqhA7m7gO1xx9hjyHpQdJucBeTSJpuQSUK20znQibc=; b=rHrhTdOv1/cRgj23QjSVUUGCg2dvdkiuSFmOCNMn0uzy0rUXK/m9b4Hc//8hazyePM seUEdYuNVTTg1ocK7CfJJdCrfnOI1+rUOJsB7dYkhzY4RdMkwWyZfIg5atuPdnPrJIVp mPCEeCPLvUlG+BCzN909fF5z98aCC7dY1jVVWDKKtC4ZmOyYF+r2Vr8Ei5y/cgsQ48Ck gp2NYkvwZeEzWLHnPvkAEsKTXJ05jtO+KVPCozfwPNWBj75FsHPiAgVWG3nOc/ox/9JB ssY0J/T0eX/2xGNCLJxTPL3sJZC7Zjk9W9eD17YKeeOK0w2/lUQXUnZ0XeunM+KtkurM em1Q== X-Gm-Message-State: AMke39leWW9pt9U9f53hfMqSe7WC+P8GLuPF1ed+gU1JAKdWBKim5lY1hySSA5WcG5qqOg== X-Received: by 10.223.136.66 with SMTP id e2mr4458355wre.14.1488322625339; Tue, 28 Feb 2017 14:57:05 -0800 (PST) Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com. [74.125.82.50]) by smtp.gmail.com with ESMTPSA id e71sm4465892wma.8.2017.02.28.14.57.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Feb 2017 14:57:05 -0800 (PST) Received: by mail-wm0-f50.google.com with SMTP id i17so5395686wmf.0; Tue, 28 Feb 2017 14:57:05 -0800 (PST) X-Received: by 10.28.218.80 with SMTP id r77mr735296wmg.0.1488322624957; Tue, 28 Feb 2017 14:57:04 -0800 (PST) MIME-Version: 1.0 Reply-To: cem@freebsd.org Received: by 10.80.152.82 with HTTP; Tue, 28 Feb 2017 14:57:04 -0800 (PST) In-Reply-To: <226a00fa-5d04-0aa7-e0cc-6078edde6639@FreeBSD.org> References: <20170228224739.167f2273@bsd64.grem.de> <226a00fa-5d04-0aa7-e0cc-6078edde6639@FreeBSD.org> From: Conrad Meyer Date: Tue, 28 Feb 2017 14:57:04 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: panic: invalid bcd xxx To: Eric van Gyzen Cc: Michael Gmelin , "freebsd-current@freebsd.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 28 Feb 2017 23:02:22 -0000 On Tue, Feb 28, 2017 at 2:31 PM, Eric van Gyzen wrote: > Your system's real-time clock is returning garbage. r312702 added some > input validation a few weeks ago. Previously, the kernel was reading beyond > the end of an array and either complaining about the clock or setting it to > the wrong time based on whatever was in the memory beyond the array. > > The added validation shouldn't be an assertion because it operates on data > beyond the kernel's control. Try this: > > --- sys/libkern.h (revision 314424) > +++ sys/libkern.h (working copy) > @@ -57,8 +57,10 @@ > bcd2bin(int bcd) > { > > - KASSERT(bcd >= 0 && bcd < LIBKERN_LEN_BCD2BIN, > - ("invalid bcd %d", bcd)); > + if (bcd < 0 || bcd >= LIBKERN_LEN_BCD2BIN) { > + printf("invalid bcd %d\n", bcd); > + return (0); > + } > return (bcd2bin_data[bcd]); > } I don't think removing this assertion and truncating to zero is the right thing to do. Adding an error return to this routine is a little much, though. I think probably the caller should perform input validation between the broken device and this routine. Thanks, Conrad