From owner-freebsd-current@freebsd.org Tue Feb 28 23:16:04 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 65AB5CF2E10 for ; Tue, 28 Feb 2017 23:16:04 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from smtp.vangyzen.net (hotblack.vangyzen.net [IPv6:2607:fc50:1000:7400:216:3eff:fe72:314f]) by mx1.freebsd.org (Postfix) with ESMTP id 50608299; Tue, 28 Feb 2017 23:16:04 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from sweettea.beer.town (unknown [76.164.8.130]) by smtp.vangyzen.net (Postfix) with ESMTPSA id 7CF885646A; Tue, 28 Feb 2017 17:16:03 -0600 (CST) Subject: Re: panic: invalid bcd xxx To: cem@freebsd.org References: <20170228224739.167f2273@bsd64.grem.de> <226a00fa-5d04-0aa7-e0cc-6078edde6639@FreeBSD.org> Cc: Michael Gmelin , "freebsd-current@freebsd.org" From: Eric van Gyzen Message-ID: Date: Tue, 28 Feb 2017 17:16:02 -0600 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit 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:16:04 -0000 On 02/28/2017 16:57, Conrad Meyer wrote: > 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. Either of those would be a much better solution. This was just a quick hack to get the memstick to boot. Eric