[PATCH] fix mac_computer

rongqing.li at windriver.com rongqing.li at windriver.com
Sun Jun 9 18:41:32 EST 2013


The mac_compute() function in openssh calls umac_final() to prepend a tag
to a buffer.  Umac_final() calls pdf_gen_xor() on the tag as its final
operation, and as implemented, pdf_gen_xor() assumes an appropriate
alignment for 64-bit operations on its buffer.  However, the buffer
is declared in mac_compute() as a static u_char array, and the linker
doesn't guarantee 64-bit alignment for such arrays.  On ARM v7 NEON
platforms with gcc, 64-bit values must be 64-bit aligned, and the
unaligned buffer declaration caused alignment faults when executing
certain openssh tests.

Force the buffer in mac_compute() to be 64-bit aligned.

Signed-off-by: Donn Seeley <donn.seeley at windriver.com>
Signed-off-by: Roy Li <rongqing.li at windriver.com>
---
 mac.c |    8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

--- a/mac.c
+++ b/mac.c
@@ -132,12 +132,14 @@ mac_init(Mac *mac)
 u_char *
 mac_compute(Mac *mac, u_int32_t seqno, u_char *data, int datalen)
 {
-	static u_char m[EVP_MAX_MD_SIZE];
+	static u_int64_t m_buf[(EVP_MAX_MD_SIZE + sizeof (u_int64_t) - 1)
+	    / sizeof (u_int64_t)];
+	u_char *m = (u_char *)m_buf;
 	u_char b[4], nonce[8];
 
-	if (mac->mac_len > sizeof(m))
+	if (mac->mac_len > EVP_MAX_MD_SIZE)
 		fatal("mac_compute: mac too long %u %lu",
-		    mac->mac_len, (u_long)sizeof(m));
+		    mac->mac_len, (u_long)EVP_MAX_MD_SIZE);
 
 	switch (mac->type) {
 	case SSH_EVP:


More information about the openssh-unix-dev mailing list