From owner-freebsd-bugs@FreeBSD.ORG Mon Mar 27 13:10:13 2006 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id BB7D316A400 for ; Mon, 27 Mar 2006 13:10:13 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 3B85A43D49 for ; Mon, 27 Mar 2006 13:10:12 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k2RDABEE072815 for ; Mon, 27 Mar 2006 13:10:11 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k2RDABTq072814; Mon, 27 Mar 2006 13:10:11 GMT (envelope-from gnats) Resent-Date: Mon, 27 Mar 2006 13:10:11 GMT Resent-Message-Id: <200603271310.k2RDABTq072814@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Stephane Sudre Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 6F42316A438 for ; Mon, 27 Mar 2006 13:04:31 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id D76D243D48 for ; Mon, 27 Mar 2006 13:04:30 +0000 (GMT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.13.1/8.13.1) with ESMTP id k2RD4Tcf057965 for ; Mon, 27 Mar 2006 13:04:29 GMT (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.13.1/8.13.1/Submit) id k2RD4T8I057962; Mon, 27 Mar 2006 13:04:29 GMT (envelope-from nobody) Message-Id: <200603271304.k2RD4T8I057962@www.freebsd.org> Date: Mon, 27 Mar 2006 13:04:29 GMT From: Stephane Sudre To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-2.3 Cc: Subject: misc/95002: hash db source code has a bug which prevents using cross-platform data base X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Mar 2006 13:10:13 -0000 >Number: 95002 >Category: misc >Synopsis: hash db source code has a bug which prevents using cross-platform data base >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Mar 27 13:10:11 GMT 2006 >Closed-Date: >Last-Modified: >Originator: Stephane Sudre >Release: Mac OS X >Organization: >Environment: Darwin Kernel Version 7.9.0: Wed Mar 30 20:11:17 PST 2005; root:xnu/xnu-517.12.7.obj~1/RELEASE_PPC Power Macintosh powerpc >Description: Project: Libc Folder: db File: hash_page.c Function: __put_page Let's imagine you have a data base created on a BIG_ENDIAN system with the lorder flag set to 0 on creation and you're updating it on a LITTLE_ENDIAN system. The lorder for the file as read on the LITTLE_ENDIAN system is 4321 (BIG_ENDIAN) so when you call __put_page, you are entering the case: hashp->LORDER != BYTE_ORDER) While the swap operation is perfect to write the data base on disk with _write, the current code is leading to a corruption of the data base because the buffer is not swapped back after writing. >How-To-Repeat: Create a hash data base on a PPC system. Open this data base on a i386 system. Update this data base with some put calls and then call sync twice. => The data base is corrupted. >Fix: AFAIK, the fix is to swap back buffer p with something like this after the call to _write (and probably also when _write call fails): if (hashp->LORDER != BYTE_ORDER) { if (is_bitmap) { for (i = 0; i < cached_max; i++) M_32_SWAP(((int *)p)[i]); } else { for (i = 0; i <= cached_max; i++) M_16_SWAP(((u_int16_t *)p)[i]); } } where cached_max is the cached value of max computed previously in __put_page. >Release-Note: >Audit-Trail: >Unformatted: