[Pkg-db-devel] Bug#437742: db: Encryption broken on arm (old ABI)
Ben Hutchings
ben at decadent.org.uk
Tue Sep 9 00:51:10 UTC 2008
I tracked this down to structure padding, which is weird on ARM.
The EINVAL comes from:
if ((data_len % DB_AES_CHUNK) != 0)
return (EINVAL);
in __aes_encrypt(), called by __db_encrypt_and_checksum_pg().
data_len is calculated as DBMETASIZE - P_OVERHEAD(dbp). For an
encrypted database this evaluates to 448, a multiple of DB_AES_CHUNK =
16. On ARM (old ABI) it evaluates to 446 because sizeof(PG_CRYPTO) is
40 and not 38 as expected.
So encrypted databases never worked on this architecture, and we should
be able to fix this up by replacing sizeof(PG_CRYPTO) with
SIZEOF_PG_CRYPTO defined to 38. A similar hack is already used for
sizeof(PAGE).
Not yet tested on ARM, as it takes about 4 hours to run the test suite
on agnesi. Will report the results when that's done.
Ben.
--- db-4.7.25.orig/dbinc/db_page.h
+++ db-4.7.25/dbinc/db_page.h
@@ -223,6 +223,17 @@
*/
} PG_CRYPTO;
+/*
+ * With most compilers sizeof(PG_CRYPTO) == 38. However some ABIs
+ * require it to be padded to 40 bytes. The padding must be excluded
+ * from our size calculations due to the 16-byte alignment requirement
+ * for crypto.
+ *
+ * A similar problem applies to PG_CHKSUM, but it's too late to change
+ * that.
+ */
+#define SIZEOF_PG_CRYPTO 38
+
typedef struct _db_page {
DB_LSN lsn; /* 00-07: Log sequence number. */
db_pgno_t pgno; /* 08-11: Current page number. */
@@ -258,7 +269,7 @@
*/
#define P_INP(dbp, pg) \
((db_indx_t *)((u_int8_t *)(pg) + SIZEOF_PAGE + \
- (F_ISSET((dbp), DB_AM_ENCRYPT) ? sizeof(PG_CRYPTO) : \
+ (F_ISSET((dbp), DB_AM_ENCRYPT) ? SIZEOF_PG_CRYPTO : \
(F_ISSET((dbp), DB_AM_CHKSUM) ? sizeof(PG_CHKSUM) : 0))))
#define P_IV(dbp, pg) \
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://lists.alioth.debian.org/pipermail/pkg-db-devel/attachments/20080909/c9a25a42/attachment.pgp
More information about the Pkg-db-devel
mailing list