Received: by 10.213.65.68 with SMTP id h4csp2113045imn; Sun, 8 Apr 2018 20:02:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx48u3St197xVSucoZCwUA0EC/fcWWOBkdQsmJ9lA41JeQ74rxpDAgCAhWTXz0tvBGdCX7sXo X-Received: by 10.99.135.199 with SMTP id i190mr23645832pge.2.1523242977048; Sun, 08 Apr 2018 20:02:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523242977; cv=none; d=google.com; s=arc-20160816; b=t4bVyOaloKEhDEnhAn0HcQMvvzwr1LHvxESo6Qr3oVu9VgTeuV2wCzlvXV9kEnKGC/ GH8ccWuSKv5/8PW55RljMqZDx2mdM7t+d8mneKOBxwOHEbeO+RNfZuz0Ss4iDNuqTBmI 0+xGld22ykxjmf28j6nijtWJrELAiUVEZJA9UOSXkajoW38ewlXrI9ZNUYumR8Ui4emD 0bdQU1U2hqEenakp/Q3DA88lBeK7MCXqff1ho9tePdCe3S66t9N7p+PtkTYUyHzyCKr2 6OIT7OHqdk1vW6oaC6teVGSROg+idC7jrOFomq9tjYR0LE+at6lWJhRGhLFh7ul8DVmg 3XkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=ysuainv3oQDH8iVH9xBwstaueW16t2MoVREE9xx2d4s=; b=mzk8xqDB4/EVB3AvQ4+r5pXkIffqqNSHsz63HoGc5AYDKUdVlCVrmRAKNtEFgQGVZ0 QRbQF1plw458GZfAfclt3tFzecxjQ47Inc63bsCzVjBH8OxPhtpxs8IpYO39xtYj590J GqtBQbQmOjvESht8nCgcsISg3p4RC0f/oHTUS3SkVKlQmKC1m+CXrN75A2+dSooieS4V wQ45w3ZPJXN4q2iLOw/JXLD0Efbjy0s2bYXFWcz46JRXJNyXt3OSjg5bULjgrqHxBPGe Jpp37inOYRUyWXhYlqFxqXGEsXTBsI6UiN2gH4Gms0PjvOGBb38HC+mV/dfKNn5WfoNu oRZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=NBhBxg1i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t137si10494228pgb.288.2018.04.08.20.02.20; Sun, 08 Apr 2018 20:02:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=NBhBxg1i; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755389AbeDIA0i (ORCPT + 99 others); Sun, 8 Apr 2018 20:26:38 -0400 Received: from mail-by2nam03on0131.outbound.protection.outlook.com ([104.47.42.131]:4960 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755332AbeDIA02 (ORCPT ); Sun, 8 Apr 2018 20:26:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ysuainv3oQDH8iVH9xBwstaueW16t2MoVREE9xx2d4s=; b=NBhBxg1imEiTvAyCjMVAlruB5yakjRyl2XyG7dSfxlGjfqSkPM5vHi+XPoIlR9/1tc/QPNcX9EqyMhbU7CYZvCb8oPWhRoIXbeb6Ud9SAmb3CDxctRXAk2cei7hCM0Y/KpzM9OR7ArtIIwhghFB878uzFnemCEZWpKkqkJLIZxA= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB0725.namprd21.prod.outlook.com (10.167.107.167) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.696.0; Mon, 9 Apr 2018 00:26:16 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8109:aef0:a777:7059%2]) with mapi id 15.20.0696.003; Mon, 9 Apr 2018 00:26:16 +0000 From: Sasha Levin To: "stable@vger.kernel.org" , "linux-kernel@vger.kernel.org" CC: David Howells , "David S . Miller" , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 143/161] rxrpc: Don't put crypto buffers on the stack Thread-Topic: [PATCH AUTOSEL for 4.14 143/161] rxrpc: Don't put crypto buffers on the stack Thread-Index: AQHTz5jABUHNkUbrzUmrhbaBNNbdAQ== Date: Mon, 9 Apr 2018 00:21:50 +0000 Message-ID: <20180409001936.162706-143-alexander.levin@microsoft.com> References: <20180409001936.162706-1-alexander.levin@microsoft.com> In-Reply-To: <20180409001936.162706-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB0725;7:HFHbPS4LVG1h5Ji01m03a7jWOGavio9puqhGTn9nOptW3Umdqn11pbQXupDujk9NP2rsLUgXBsg5nsznLea3YDS6bVsZDZ4NdIZE59Uq04/b/Rdh6Le3+nvpNNkSxHsAOQsvw9/RKGbfoek1ZbMBnNG+CvMakt3qB0s3T6NdHtILrR+PMePGyBcbBo0+VspsB1LjNQGJPKFdbBRUM+4CCqcBqZ+T0fJXXo+qMyZ4Zqmc3MpmEDsbLUv6uMQgX54O;20:N6yWcwy8GeF++9dv8rqvQN2b34vSjS9cWLOvmXMdgrl5R1f1tRAcHlVVUU8Ons4BQjzn6GficYocxUOYQc0RwTjAd+WrzD9tF6YnBdf3gO9Y36potUfrleBnSXTxXWe7aNyJdJwbLCEu5nDyoolWHDkkAMwJMnsXa/5ETg2+/pQ= x-ms-office365-filtering-ht: Tenant X-MS-Office365-Filtering-Correlation-Id: 3719a51c-2167-4b89-3cea-08d59db0822d x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB0725; x-ms-traffictypediagnostic: DM5PR2101MB0725: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(158342451672863)(89211679590171)(192374486261705)(17755550239193); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3231221)(944501327)(52105095)(93006095)(93001095)(3002001)(6055026)(61426038)(61427038)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011);SRVR:DM5PR2101MB0725;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB0725; x-forefront-prvs: 0637FCE711 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(39380400002)(346002)(366004)(376002)(396003)(39860400002)(199004)(189003)(6486002)(81166006)(26005)(6512007)(4326008)(6666003)(6436002)(81156014)(8676002)(97736004)(186003)(36756003)(72206003)(53936002)(107886003)(2906002)(86362001)(76176011)(110136005)(305945005)(10090500001)(486006)(3660700001)(102836004)(5660300001)(14454004)(476003)(575784001)(86612001)(446003)(99286004)(68736007)(66066001)(11346002)(54906003)(2616005)(1076002)(7736002)(5250100002)(25786009)(8936002)(478600001)(2900100001)(2501003)(3280700002)(105586002)(59450400001)(316002)(106356001)(22452003)(6506007)(3846002)(10290500003)(6116002)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB0725;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: IQaX9vd+FuNig779NZos3HEaeLOXtcrFSD0BUUEbrtaVUvUe78DUkqfBcPRjkLmIdQ5obpDI74ZeI45axtKO7bT8C+4QoRm7ccswCw7EB8dJa84SDdKYsLWEORI+AccN04kvabUAaO2tSRlOjlohMzPdx0RmK1Mox4/FHUFgYy7fqBx+nj8pPGewNvHxD108WEVI729/Hqc4nKLOGY6mPgwg9uTsFyeoI3vx4T/mZqdqCl9aCE0DCtFRilLoU51pZq+NYFl1+7Gv715hD4kJL8DuNTBLofk6wPcjzbe95kFebDzs96t63oGPGq4Q01Pzk7mnFb5T1n0Xl4AtBhsYTFmaz6BLIUHcbQl5X8UJ/6NpfuiGvKPjL1v1c4u77Qk55GdqIm6qIRApaZX6jimsdoZD9+P7Kj9Y7ztxVpfjQX0= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3719a51c-2167-4b89-3cea-08d59db0822d X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Apr 2018 00:21:50.1436 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB0725 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Howells [ Upstream commit 8c2f826dc36314059ac146c78d3bf8056b626446 ] Don't put buffers of data to be handed to crypto on the stack as this may cause an assertion failure in the kernel (see below). Fix this by using an kmalloc'd buffer instead. kernel BUG at ./include/linux/scatterlist.h:147! ... RIP: 0010:rxkad_encrypt_response.isra.6+0x191/0x1b0 [rxrpc] RSP: 0018:ffffbe2fc06cfca8 EFLAGS: 00010246 RAX: 0000000000000000 RBX: ffff989277d59900 RCX: 0000000000000028 RDX: 0000259dc06cfd88 RSI: 0000000000000025 RDI: ffffbe30406cfd88 RBP: ffffbe2fc06cfd60 R08: ffffbe2fc06cfd08 R09: ffffbe2fc06cfd08 R10: 0000000000000000 R11: 0000000000000000 R12: 1ffff7c5f80d9f95 R13: ffffbe2fc06cfd88 R14: ffff98927a3f7aa0 R15: ffffbe2fc06cfd08 FS: 0000000000000000(0000) GS:ffff98927fc00000(0000) knlGS:000000000000000= 0 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 000055b1ff28f0f8 CR3: 000000001b412003 CR4: 00000000003606f0 DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000 DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400 Call Trace: rxkad_respond_to_challenge+0x297/0x330 [rxrpc] rxrpc_process_connection+0xd1/0x690 [rxrpc] ? process_one_work+0x1c3/0x680 ? __lock_is_held+0x59/0xa0 process_one_work+0x249/0x680 worker_thread+0x3a/0x390 ? process_one_work+0x680/0x680 kthread+0x121/0x140 ? kthread_create_worker_on_cpu+0x70/0x70 ret_from_fork+0x3a/0x50 Reported-by: Jonathan Billings Reported-by: Marc Dionne Signed-off-by: David Howells Tested-by: Jonathan Billings Signed-off-by: David S. Miller Signed-off-by: Sasha Levin --- net/rxrpc/conn_event.c | 1 + net/rxrpc/rxkad.c | 92 ++++++++++++++++++++++++++++------------------= ---- 2 files changed, 52 insertions(+), 41 deletions(-) diff --git a/net/rxrpc/conn_event.c b/net/rxrpc/conn_event.c index 59a51a56e7c8..0435c4167a1a 100644 --- a/net/rxrpc/conn_event.c +++ b/net/rxrpc/conn_event.c @@ -404,6 +404,7 @@ void rxrpc_process_connection(struct work_struct *work) case -EKEYEXPIRED: case -EKEYREJECTED: goto protocol_error; + case -ENOMEM: case -EAGAIN: goto requeue_and_leave; case -ECONNABORTED: diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c index c38b3a1de56c..77cb23c7bd0a 100644 --- a/net/rxrpc/rxkad.c +++ b/net/rxrpc/rxkad.c @@ -773,8 +773,7 @@ static int rxkad_respond_to_challenge(struct rxrpc_conn= ection *conn, { const struct rxrpc_key_token *token; struct rxkad_challenge challenge; - struct rxkad_response resp - __attribute__((aligned(8))); /* must be aligned for crypto */ + struct rxkad_response *resp; struct rxrpc_skb_priv *sp =3D rxrpc_skb(skb); const char *eproto; u32 version, nonce, min_level, abort_code; @@ -818,26 +817,29 @@ static int rxkad_respond_to_challenge(struct rxrpc_co= nnection *conn, token =3D conn->params.key->payload.data[0]; =20 /* build the response packet */ - memset(&resp, 0, sizeof(resp)); - - resp.version =3D htonl(RXKAD_VERSION); - resp.encrypted.epoch =3D htonl(conn->proto.epoch); - resp.encrypted.cid =3D htonl(conn->proto.cid); - resp.encrypted.securityIndex =3D htonl(conn->security_ix); - resp.encrypted.inc_nonce =3D htonl(nonce + 1); - resp.encrypted.level =3D htonl(conn->params.security_level); - resp.kvno =3D htonl(token->kad->kvno); - resp.ticket_len =3D htonl(token->kad->ticket_len); - - resp.encrypted.call_id[0] =3D htonl(conn->channels[0].call_counter); - resp.encrypted.call_id[1] =3D htonl(conn->channels[1].call_counter); - resp.encrypted.call_id[2] =3D htonl(conn->channels[2].call_counter); - resp.encrypted.call_id[3] =3D htonl(conn->channels[3].call_counter); + resp =3D kzalloc(sizeof(struct rxkad_response), GFP_NOFS); + if (!resp) + return -ENOMEM; + + resp->version =3D htonl(RXKAD_VERSION); + resp->encrypted.epoch =3D htonl(conn->proto.epoch); + resp->encrypted.cid =3D htonl(conn->proto.cid); + resp->encrypted.securityIndex =3D htonl(conn->security_ix); + resp->encrypted.inc_nonce =3D htonl(nonce + 1); + resp->encrypted.level =3D htonl(conn->params.security_level); + resp->kvno =3D htonl(token->kad->kvno); + resp->ticket_len =3D htonl(token->kad->ticket_len); + resp->encrypted.call_id[0] =3D htonl(conn->channels[0].call_counter); + resp->encrypted.call_id[1] =3D htonl(conn->channels[1].call_counter); + resp->encrypted.call_id[2] =3D htonl(conn->channels[2].call_counter); + resp->encrypted.call_id[3] =3D htonl(conn->channels[3].call_counter); =20 /* calculate the response checksum and then do the encryption */ - rxkad_calc_response_checksum(&resp); - rxkad_encrypt_response(conn, &resp, token->kad); - return rxkad_send_response(conn, &sp->hdr, &resp, token->kad); + rxkad_calc_response_checksum(resp); + rxkad_encrypt_response(conn, resp, token->kad); + ret =3D rxkad_send_response(conn, &sp->hdr, resp, token->kad); + kfree(resp); + return ret; =20 protocol_error: trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, eproto); @@ -1048,8 +1050,7 @@ static int rxkad_verify_response(struct rxrpc_connect= ion *conn, struct sk_buff *skb, u32 *_abort_code) { - struct rxkad_response response - __attribute__((aligned(8))); /* must be aligned for crypto */ + struct rxkad_response *response; struct rxrpc_skb_priv *sp =3D rxrpc_skb(skb); struct rxrpc_crypt session_key; const char *eproto; @@ -1061,17 +1062,22 @@ static int rxkad_verify_response(struct rxrpc_conne= ction *conn, =20 _enter("{%d,%x}", conn->debug_id, key_serial(conn->server_key)); =20 + ret =3D -ENOMEM; + response =3D kzalloc(sizeof(struct rxkad_response), GFP_NOFS); + if (!response) + goto temporary_error; + eproto =3D tracepoint_string("rxkad_rsp_short"); abort_code =3D RXKADPACKETSHORT; if (skb_copy_bits(skb, sizeof(struct rxrpc_wire_header), - &response, sizeof(response)) < 0) + response, sizeof(*response)) < 0) goto protocol_error; - if (!pskb_pull(skb, sizeof(response))) + if (!pskb_pull(skb, sizeof(*response))) BUG(); =20 - version =3D ntohl(response.version); - ticket_len =3D ntohl(response.ticket_len); - kvno =3D ntohl(response.kvno); + version =3D ntohl(response->version); + ticket_len =3D ntohl(response->ticket_len); + kvno =3D ntohl(response->kvno); _proto("Rx RESPONSE %%%u { v=3D%u kv=3D%u tl=3D%u }", sp->hdr.serial, version, kvno, ticket_len); =20 @@ -1105,31 +1111,31 @@ static int rxkad_verify_response(struct rxrpc_conne= ction *conn, ret =3D rxkad_decrypt_ticket(conn, skb, ticket, ticket_len, &session_key, &expiry, _abort_code); if (ret < 0) - goto temporary_error_free; + goto temporary_error_free_resp; =20 /* use the session key from inside the ticket to decrypt the * response */ - rxkad_decrypt_response(conn, &response, &session_key); + rxkad_decrypt_response(conn, response, &session_key); =20 eproto =3D tracepoint_string("rxkad_rsp_param"); abort_code =3D RXKADSEALEDINCON; - if (ntohl(response.encrypted.epoch) !=3D conn->proto.epoch) + if (ntohl(response->encrypted.epoch) !=3D conn->proto.epoch) goto protocol_error_free; - if (ntohl(response.encrypted.cid) !=3D conn->proto.cid) + if (ntohl(response->encrypted.cid) !=3D conn->proto.cid) goto protocol_error_free; - if (ntohl(response.encrypted.securityIndex) !=3D conn->security_ix) + if (ntohl(response->encrypted.securityIndex) !=3D conn->security_ix) goto protocol_error_free; - csum =3D response.encrypted.checksum; - response.encrypted.checksum =3D 0; - rxkad_calc_response_checksum(&response); + csum =3D response->encrypted.checksum; + response->encrypted.checksum =3D 0; + rxkad_calc_response_checksum(response); eproto =3D tracepoint_string("rxkad_rsp_csum"); - if (response.encrypted.checksum !=3D csum) + if (response->encrypted.checksum !=3D csum) goto protocol_error_free; =20 spin_lock(&conn->channel_lock); for (i =3D 0; i < RXRPC_MAXCALLS; i++) { struct rxrpc_call *call; - u32 call_id =3D ntohl(response.encrypted.call_id[i]); + u32 call_id =3D ntohl(response->encrypted.call_id[i]); =20 eproto =3D tracepoint_string("rxkad_rsp_callid"); if (call_id > INT_MAX) @@ -1153,12 +1159,12 @@ static int rxkad_verify_response(struct rxrpc_conne= ction *conn, =20 eproto =3D tracepoint_string("rxkad_rsp_seq"); abort_code =3D RXKADOUTOFSEQUENCE; - if (ntohl(response.encrypted.inc_nonce) !=3D conn->security_nonce + 1) + if (ntohl(response->encrypted.inc_nonce) !=3D conn->security_nonce + 1) goto protocol_error_free; =20 eproto =3D tracepoint_string("rxkad_rsp_level"); abort_code =3D RXKADLEVELFAIL; - level =3D ntohl(response.encrypted.level); + level =3D ntohl(response->encrypted.level); if (level > RXRPC_SECURITY_ENCRYPT) goto protocol_error_free; conn->params.security_level =3D level; @@ -1168,9 +1174,10 @@ static int rxkad_verify_response(struct rxrpc_connec= tion *conn, * as for a client connection */ ret =3D rxrpc_get_server_data_key(conn, &session_key, expiry, kvno); if (ret < 0) - goto temporary_error_free; + goto temporary_error_free_ticket; =20 kfree(ticket); + kfree(response); _leave(" =3D 0"); return 0; =20 @@ -1179,12 +1186,15 @@ protocol_error_unlock: protocol_error_free: kfree(ticket); protocol_error: + kfree(response); trace_rxrpc_rx_eproto(NULL, sp->hdr.serial, eproto); *_abort_code =3D abort_code; return -EPROTO; =20 -temporary_error_free: +temporary_error_free_ticket: kfree(ticket); +temporary_error_free_resp: + kfree(response); temporary_error: /* Ignore the response packet if we got a temporary error such as * ENOMEM. We just want to send the challenge again. Note that we --=20 2.15.1