From patchwork Wed Oct 21 12:36:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sowmini Varadhan X-Patchwork-Id: 7456551 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6710E9F1C3 for ; Wed, 21 Oct 2015 12:36:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 86E84208C8 for ; Wed, 21 Oct 2015 12:36:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8344F20457 for ; Wed, 21 Oct 2015 12:36:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932157AbbJUMgz (ORCPT ); Wed, 21 Oct 2015 08:36:55 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:27218 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751701AbbJUMgy (ORCPT ); Wed, 21 Oct 2015 08:36:54 -0400 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id t9LCaV7j006875 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 21 Oct 2015 12:36:32 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0021.oracle.com (8.13.8/8.13.8) with ESMTP id t9LCaVqM010474 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL); Wed, 21 Oct 2015 12:36:31 GMT Received: from abhmp0015.oracle.com (abhmp0015.oracle.com [141.146.116.21]) by userv0121.oracle.com (8.13.8/8.13.8) with ESMTP id t9LCaTlm017032; Wed, 21 Oct 2015 12:36:29 GMT Received: from oracle.com (/10.154.133.169) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 21 Oct 2015 05:36:29 -0700 Date: Wed, 21 Oct 2015 08:36:28 -0400 From: Sowmini Varadhan To: Steffen Klassert Cc: linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, herbert@gondor.apana.org.au, dhowells@redhat.com, davem@davemloft.net, 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 Message-ID: <20151021123628.GP6948@oracle.com> References: <65f37efeff5af105c89493dda4f38c61e4cd495f.1445286755.git.sowmini.varadhan@oracle.com> <20151021065704.GM7701@secunet.com> <20151021105442.GM6948@oracle.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20151021105442.GM6948@oracle.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On (10/21/15 06:54), Sowmini Varadhan wrote: > But __alignof__(*p) is 8 on sparc, and without the patch I get > all types of unaligned access. So what do you suggest as the fix? Even though the alignment is, in fact, 8 (and that comes from struct xfrm_lifetime_cfg), if uspace is firmly attached to the 4 byte alignment, I think we can retain that behavior and still avoid unaligned access in the kernel with the following (admittedly ugly hack). Can you please take a look? I tested it with 'ip x m' and a transport mode tunnel on my sparc. --- To unsubscribe from this list: send the line "unsubscribe linux-crypto" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c index 158ef4a..ca4e7f0 100644 --- a/net/xfrm/xfrm_user.c +++ b/net/xfrm/xfrm_user.c @@ -2620,7 +2620,7 @@ static inline size_t xfrm_sa_len(struct xfrm_state *x) static int xfrm_notify_sa(struct xfrm_state *x, const struct km_event *c) { struct net *net = xs_net(x); - struct xfrm_usersa_info *p; + struct xfrm_usersa_info *p, tmp; struct xfrm_usersa_id *id; struct nlmsghdr *nlh; struct sk_buff *skb; @@ -2659,11 +2659,16 @@ static int xfrm_notify_sa(struct xfrm_state *x, const struct km_event *c) if (attr == NULL) goto out_free_skb; - p = PTR_ALIGN(nla_data(attr), __alignof__(*p)); + p = nla_data(attr); + err = copy_to_user_state_extra(x, &tmp, skb); + if (err) + goto out_free_skb; + memcpy((u8 *)p, &tmp, sizeof(tmp)); + } else { + err = copy_to_user_state_extra(x, p, skb); + if (err) + goto out_free_skb; } - err = copy_to_user_state_extra(x, p, skb); - if (err) - goto out_free_skb; nlmsg_end(skb, nlh);