Received: by 10.223.185.116 with SMTP id b49csp2329190wrg; Thu, 22 Feb 2018 11:55:55 -0800 (PST) X-Google-Smtp-Source: AH8x225/KTS0u4mprH21a1jyFriVpwQRMYuVaXeV15b94qJAjRGcV3H05rrNjNbiei63llF0gnfL X-Received: by 10.98.75.206 with SMTP id d75mr8009950pfj.77.1519329355645; Thu, 22 Feb 2018 11:55:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519329355; cv=none; d=google.com; s=arc-20160816; b=a3gvgL34vRTi5WXAZlBIUI/pavYx0ohIhF6yBZ6miRHn9Az/6NITnfV8dGvzwpyvbN vcBLa+FBr6xGgtUHg1Mz734GjaLohk+eyrkHVrDuTygm00FTG1Y9VWAcpBSORb06meL3 jw6YaEXb2Er2ASx4cUXXfs8Hw+Bzz/XSPjIp7dPoqQFJaJw2S7hx+L02XLNKvJ8YKY2m I0LX6LrhZXw2+5z0pdfNxfql7OzeaLssJqE1VaCJsj5it84qZ5VvUTuof+ppwauTXXZm aT7Hs3BlWuuJy6wlX53SvkrgfU0votkt6TjIZ60xuoAFgF9DFFi4zxPxD8zlnPY4UI3P 1r0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=pvAht3xO/9CnkWZnJZOvDwXQkhO2qUSSjxjgHZVvc6w=; b=aVqSk1hyTpm2DsSuRM2NKNk/0rO4BOIB4jPg30C5qFQ18XTaYM0zANDt3C5q5ePshn tDrTcOsVrYK2/1CQ29CASEYAkIARF6LrwpVBLK8jzxvBfGKjFO+Er/3/Du3ZJ4VPTUqP 7iNhbvfJ34veeXWMEZW0IRqVsjl57Ur5REuewfWBPDkRA3vIkHjwb9lT5E18vySfUnMN jDm84EGPd+wRlwffyopSQH1YbNTDsrVnTEmhvfUOaR+M8RqFnx82if0839mF/a4K/vAh RwgbzAFN3gmc8GpW0/9NBHsRLbPRD2nnRR48zY1EnQXKApDBA3gtuNS97ExYMJzEq77U PghQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p12-v6si494574pls.66.2018.02.22.11.55.41; Thu, 22 Feb 2018 11:55:55 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751367AbeBVTy6 (ORCPT + 99 others); Thu, 22 Feb 2018 14:54:58 -0500 Received: from s3.sipsolutions.net ([144.76.63.242]:46070 "EHLO sipsolutions.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751273AbeBVTy5 (ORCPT ); Thu, 22 Feb 2018 14:54:57 -0500 Received: by sipsolutions.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1eowx8-0005Pg-Io; Thu, 22 Feb 2018 20:54:50 +0100 Message-ID: <1519329289.2637.12.camel@sipsolutions.net> Subject: Re: nla_put_string() vs NLA_STRING From: Johannes Berg To: Kees Cook , Thomas Graf Cc: Daniel Borkmann , Alexei Starovoitov , Network Development , LKML , Daniel Micay Date: Thu, 22 Feb 2018 20:54:49 +0100 In-Reply-To: (sfid-20180221_070030_986418_27F469F1) References: (sfid-20180221_070030_986418_27F469F1) Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.2-1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2018-02-20 at 22:00 -0800, Kees Cook wrote: > It seems that in at least one case[1], nla_put_string() is being used > on an NLA_STRING, which lacks a NULL terminator, which leads to > silliness when nla_put_string() uses strlen() to figure out the size: Fun! I'm not a big fan of the whole NLA_STRING thing with or without NUL terminator anyway, it's a bit confusing at times :-) > This is a problem at least here: > > struct regulatory_request { > ... > char alpha2[2]; > ... > > static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { > ... > [NL80211_ATTR_REG_ALPHA2] = { .type = NLA_STRING, .len = 2 }, > ... Yeah, this is clearly stupid. We already fixed one of these, see commit a5fe8e7695dc ("regulatory: add NUL to alpha2"). I'll fix up the second one too. > So, this specific problem needs fixing (in at least two places calling > nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, ...)). While I suspect > it's only ever written an extra byte from the following variable in > the structure which is an enum nl80211_dfs_regions, Only one, since the other has alpha2[3] already :-) And in that case, yes, on little endian and only if the dfs region is non-zero, though the dfs region was added later so dunno what else there was - but certainly this struct would have always contained some enum value that had zero-bytes. > I worry there > might be a lot more of these (though I'd hope unterminated strings are > uncommon for internal representation). Generally they are, I'd argue. > And more generally, it seems > like only the NLA _input_ functions actually check nla_policy details. > It seems that the output functions should do the same too, yes? It doesn't really work that way - there's no real guarantee that the policy is symmetric on input/output. johannes