From patchwork Thu Dec 7 01:42:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Ettle X-Patchwork-Id: 10097509 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 29146602BF for ; Thu, 7 Dec 2017 01:42:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 158E92A1E6 for ; Thu, 7 Dec 2017 01:42:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 091CA2A216; Thu, 7 Dec 2017 01:42:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 494952A1E6 for ; Thu, 7 Dec 2017 01:42:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752059AbdLGBmC (ORCPT ); Wed, 6 Dec 2017 20:42:02 -0500 Received: from mout.kundenserver.de ([212.227.126.131]:63024 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751718AbdLGBmB (ORCPT ); Wed, 6 Dec 2017 20:42:01 -0500 Received: from kowalski.cb.ettle ([51.9.57.50]) by mrelayeu.kundenserver.de (mreue001 [212.227.15.163]) with ESMTPSA (Nemesis) id 0MFDJ5-1eGzts3Nvf-00GGHd; Thu, 07 Dec 2017 02:41:59 +0100 Subject: Re: Unaligned access in gss_{get,verify}_mic_v2() on sparc64 Cc: sparclinux@vger.kernel.org References: <55549068-2605-7f71-ccef-c102d6fd69ab@ettle.org.uk> <20171206190936.GB5875@fieldses.org> To: linux-nfs@vger.kernel.org From: James Ettle Message-ID: <8d4f1809-5027-46e7-1d21-d55f93950693@ettle.org.uk> Date: Thu, 7 Dec 2017 01:42:03 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171206190936.GB5875@fieldses.org> Content-Language: en-GB X-Provags-ID: V03:K0:GmSsoP05cL93sfW8GUIMv+Dc+t13hMOh07NYZSFUKKfRfbhEoxw S4rudsPfIvyu8ocd6iSYAj0ibECUqk99MZu0LMs8ypuIlRdo01f9+67y+nio9o0cU9YzlqS nodsIkHjaoOlt9SAvqr5quLa3ppid1E/2ALlFDRgX9xPspSMAAarZAYFwgTHxe9a56H0M1C 6q7hAJqW3KUKuIUj6oi4Q== X-UI-Out-Filterresults: notjunk:1; V01:K0:7bnCbcrfddg=:mzMKKn29O8WqLmEbMJeoOY susAScUpdzChim5Oe/BhSq0MtPFpN22Gr2hp80poaWaydjdGWQUyq5XPNJvy1DwmkJV+onz5y HFqj3U/I2mkDWlbCHChjFEx5zzO3Kq4HC8iHW1JExq4bf5SzJ4IquIotrVsGn80eob6MlrbBr Hcq0HvI3f3FM/CEO//LKUDzNkigbHB1q1wCpN3HJrfyx7tu+uBuNF9AntqtoL06i35Esxbxo9 wVLgFztDznn/LzhSw8CLVyDMlP0r/B2gDxlWBwQZB75xDslBj5rJ/LWoTm+9/NRx/9hXId+9b JM1JoyMqF4D+Fb5YvIPtmaqQhM9wUoN81H5P/tOZZPZ/x0P5WPaXqE3VAicAunNUfWNwQALxl 39zQ+vNXiHtpDSX801yIM9bKzRpaIn+gSRiIrPMRjznGRp1QNa1CKb+uXd01qC1WsWmRxDQJl OiSlvRr+3Q8dR+EVVSNhXRvJvXMx7XK36YQZ2PoiUJYpat0ezYhOmhYcoymJGe+qbMQbSi42E 48F2rYD6/e+6Di75O1Hme30/2w0HwXB6fIBHyf9rUGk0EhWCbQ7rluqnYpBspesrMrf0RRGrW gPqbDEvumcnuGmW8+kB4EQjde7xd4PFNXWw9NLsKW/Wa/kTJEqnOouvE+694h45W8Pxz0gurR qLcAswKFDY1ziVLwRTyT6763DGNXpUlo3ZMgXDFSZ638KMbNZIWIhIJrpM0wKi0krF5zjigpa 6l8QNqRPsJhTzoIL823lAaeSJFMOR4eJ8fG8lJ9ZngoyVVgbv+EGkN6eOw4= Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Patch from git as instructed: commit a90324ca784dea5a7259a2672c24626f5c03f576 Author: James Ettle Date: Thu Dec 7 00:50:28 2017 +0000 Fix unaligned access on sparc64. On 06/12/17 19:09, J. Bruce Fields wrote: > On Sat, Dec 02, 2017 at 11:28:18PM +0000, James Ettle wrote: >> I've been using nfs4 with krb5 on sparc64 with kernel 4.13 and 4.14 and >> seeing a lot of messages like: >> >> sparky kernel: [ 105.262927] Kernel unaligned access at TPC[10afb234] >> gss_get_mic_kerberos+0xd4/0x360 [rpcsec_gss_krb5] >> >> I've traced this down to gss_get_mic_v2() in gss_krb5_seal.c. I think >> the suspicious line is: >> >> *((__be64 *)(krb5_hdr + 8)) = cpu_to_be64(seq_send); >> >> krb5_hdr is void*, but comes from a u16 so won't generally have __be64 >> alignment. As an experiment I added local variable >> >> __be64 seq_send_be64; >> >> and replaced the cpu_to_be64 line with: >> >> seq_send_be64 = cpu_to_be64(seq_send); >> memcpy(krb5_hdr + 8, (char *) &seq_send_be64, 8); >> >> There's another one in gss_verify_mic_v2() in gss_krb5_unseal.c. Here >> there's a line >> >> if (be16_to_cpu(*((__be16 *)ptr)) != KG2_TOK_MIC) >> >> but ptr is a u8*. For this I added local variable >> >> __be16 data_be16; >> >> and replaced the above if() with >> >> memcpy((void *) &data_be16, (char *) ptr, 2); >> if (be16_to_cpu(data_be16) != KG2_TOK_MIC) >> >> I've not seen any misalignment complaints yet with this. >> >> I apologise for not sending this in the form of a patch, but this is >> only a sketch solution. I'm not a kernel hacker and I'm sure someone >> else will make a proper job of it! > > Probably so. But it might get done sooner if you do it. There's the > added benefit that you can test the exact patch that gets applied. You > can just: > > git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git > > git commit -a > > > then send us the output of "git show". > > --b. > --- To unsubscribe from this list: send the line "unsubscribe linux-nfs" 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/sunrpc/auth_gss/gss_krb5_seal.c b/net/sunrpc/auth_gss/gss_krb5_seal.c index 1d74d653e6c0..94a2b3f082a8 100644 --- a/net/sunrpc/auth_gss/gss_krb5_seal.c +++ b/net/sunrpc/auth_gss/gss_krb5_seal.c @@ -177,6 +177,7 @@ gss_get_mic_v2(struct krb5_ctx *ctx, struct xdr_buf *text, u64 seq_send; u8 *cksumkey; unsigned int cksum_usage; + __be64 seq_send_be64; dprintk("RPC: %s\n", __func__); @@ -187,7 +188,9 @@ gss_get_mic_v2(struct krb5_ctx *ctx, struct xdr_buf *text, spin_lock(&krb5_seq_lock); seq_send = ctx->seq_send64++; spin_unlock(&krb5_seq_lock); - *((__be64 *)(krb5_hdr + 8)) = cpu_to_be64(seq_send); + + seq_send_be64 = cpu_to_be64(seq_send); + memcpy(krb5_hdr + 8, (char *) &seq_send_be64, 8); if (ctx->initiate) { cksumkey = ctx->initiator_sign; diff --git a/net/sunrpc/auth_gss/gss_krb5_unseal.c b/net/sunrpc/auth_gss/gss_krb5_unseal.c index dcf9515d9aef..8ea6e30d6f3f 100644 --- a/net/sunrpc/auth_gss/gss_krb5_unseal.c +++ b/net/sunrpc/auth_gss/gss_krb5_unseal.c @@ -155,10 +155,12 @@ gss_verify_mic_v2(struct krb5_ctx *ctx, u8 flags; int i; unsigned int cksum_usage; - + __be16 be16_ptr; + dprintk("RPC: %s\n", __func__); - if (be16_to_cpu(*((__be16 *)ptr)) != KG2_TOK_MIC) + memcpy(&be16_ptr, (char *) ptr, 2); + if (be16_to_cpu(be16_ptr) != KG2_TOK_MIC) return GSS_S_DEFECTIVE_TOKEN; flags = ptr[2];