From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754951AbbJUNFz (ORCPT ); Wed, 21 Oct 2015 09:05:55 -0400 Received: from shards.monkeyblade.net ([149.20.54.216]:43817 "EHLO shards.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753329AbbJUNFy (ORCPT ); Wed, 21 Oct 2015 09:05:54 -0400 Date: Wed, 21 Oct 2015 06:22:13 -0700 (PDT) Message-Id: <20151021.062213.273447452472704627.davem@davemloft.net> To: sowmini.varadhan@oracle.com Cc: steffen.klassert@secunet.com, linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, herbert@gondor.apana.org.au, dhowells@redhat.com, zohar@linux.vnet.ibm.com, David.Woodhouse@intel.com Subject: Re: [PATCH net-next 2/2] xfrm: Fix unaligned access in xfrm_notify_sa() for DELSA From: David Miller In-Reply-To: <20151021123628.GP6948@oracle.com> References: <20151021065704.GM7701@secunet.com> <20151021105442.GM6948@oracle.com> <20151021123628.GP6948@oracle.com> X-Mailer: Mew version 6.4 on Emacs 23.4 / Mule 6.0 (HANACHIRUSATO) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.5.12 (shards.monkeyblade.net [149.20.54.216]); Wed, 21 Oct 2015 06:05:53 -0700 (PDT) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sowmini Varadhan Date: Wed, 21 Oct 2015 08:36:28 -0400 > + memcpy((u8 *)p, &tmp, sizeof(tmp)); memcpy() _never_ works for avoiding unaligned accessed. I repeat, no matter what you do, no matter what kinds of casts or fancy typing you use, memcpy() _never_ works for this purpose. The compiler knows that the pointer you are using is supposed to be at least 8 byte aligned, it can look through the cast and that's completely legitimate for it to do. So it can legitimately inline emit loads and stores to implement the memcpy() and those will still get the unaligned accesses. There is one and only one portable way to access unaligned data, and that is with the get_unaligned() and put_unaligned() helpers. Userland must do something similar to deal with this situation as well.