From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Robert Pluim Newsgroups: gmane.emacs.devel Subject: Re: The netsec thread Date: Mon, 29 Jul 2019 16:02:11 +0200 Message-ID: References: <83h8kqwukq.fsf@gnu.org> <86zhyh7nli.fsf@gmail.com> <86pnzdrn8u.fsf@gmail.com> <834l36koak.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="198544"; mail-complaints-to="usenet@blaine.gmane.org" Cc: emacs-devel@gnu.org To: Lars Ingebrigtsen Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon Jul 29 16:02:40 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hs6EY-000pVU-Hb for ged-emacs-devel@m.gmane.org; Mon, 29 Jul 2019 16:02:38 +0200 Original-Received: from localhost ([::1]:52442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hs6EX-0004NJ-FN for ged-emacs-devel@m.gmane.org; Mon, 29 Jul 2019 10:02:37 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:49505) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hs6ED-0004N9-GU for emacs-devel@gnu.org; Mon, 29 Jul 2019 10:02:18 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hs6EC-0002nS-4U for emacs-devel@gnu.org; Mon, 29 Jul 2019 10:02:17 -0400 Original-Received: from mail-wm1-x330.google.com ([2a00:1450:4864:20::330]:51171) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hs6EB-0002mv-Tg for emacs-devel@gnu.org; Mon, 29 Jul 2019 10:02:16 -0400 Original-Received: by mail-wm1-x330.google.com with SMTP id v15so53990936wml.0 for ; Mon, 29 Jul 2019 07:02:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:mail-copies-to:gmane-reply-to-list :date:message-id:mime-version:content-transfer-encoding; bh=7JnQbxxTubbiMxGUFb01tXBG2R6Xi0VioN4qLs0DY0U=; b=oBc9cBAsic8bOiufWMtJsGNwc3orNs3MUb86TkhCNh0jLbtgiVgAswwxefM84zPsIk 0VX+vOuaGocOvhu31QZ60gHlX3KM6WrSfsfhh7deV4JCNkL0fBLTkhLuYUdHr+/AyMaV vBGKUfqYck5Z1dyEGeH48rIm4bQF2q1YFM9Vr/nMgPkzVrt5zm3hMbZGq3XixqJiwwUE S5AmNPk6UMv9kQeMwE/oYVmKyhSon/p8YTF9Bazk48RnEC6TBL4ukrv6JDoaRfjW+g1O ej3C5Rf+Mli67qR2igQf114/vM6dyaCpsfKz3SAROl1Sv45MOCRHDwC/pPIB47dHHdr8 1hSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:mail-copies-to :gmane-reply-to-list:date:message-id:mime-version :content-transfer-encoding; bh=7JnQbxxTubbiMxGUFb01tXBG2R6Xi0VioN4qLs0DY0U=; b=U2hfczzLcSRZ0mJN+xCKemX4OBsNNHTbpbIDafs7ZyruicTtdj33dLrjpDG0SCzP1e 0G0CpP1G/4F1h0YRdtAgyAhtnlctZMtTpo21Fo3T9lb1hGvDa3yfuFtmGIXKl76qGg1S ARQKihB+KvyYx3XZuWjjCpCw+CqmITR6NLW5fprFGSmLqxUFGzUUbTqlpaP6moYebbF+ L1IxNJM1YenSrnKIboxyUb3ggnWsvE/eTVfnhMPPoniSdrRUoRym0xE0Az7xV49ND1fx 6MeKju7DiHOXXowBS4AGbn2dml5Olzxz1xAfOjnnHbRXkdAcPbhwSG+ufQ5FsyQJgM84 +ncQ== X-Gm-Message-State: APjAAAWQsSuW+lhByKQ887nJXIB50sROndanqXru/OkjjZEFJ86KU+VI hLz0PNg6D628241Tzsyqe67HQlDC X-Google-Smtp-Source: APXvYqxZ2pa6zOsPmx7PpS54CuvG/oRuoQzq8Mc14a+YtSZ34BM8Zg3E24rb0Kq1bfG3HiuXu5ML5w== X-Received: by 2002:a05:600c:20d:: with SMTP id 13mr100313867wmi.141.1564408934136; Mon, 29 Jul 2019 07:02:14 -0700 (PDT) Original-Received: from rpluim-mac ([149.5.228.1]) by smtp.gmail.com with ESMTPSA id j6sm87514048wrx.46.2019.07.29.07.02.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 29 Jul 2019 07:02:12 -0700 (PDT) Mail-Copies-To: never Gmane-Reply-To-List: yes X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::330 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:238994 Archived-At: >>>>> On Mon, 29 Jul 2019 13:14:44 +0200, Lars Ingebrigtsen said: Lars> Robert Pluim writes: >> I had some issues with nsm-trust-local-network as a concept and also >> the IP addresses it checked. And 0.0.0.0/8 is now a valid range (on >> very recent Linux kernels anyway), so that test needs adjusting. Lars> Oh, yeah, I had forgotten about that bit. Yes, I wasn't convince= d about Lars> that bit, either. >> Did I send a patch for that? I don=CA=BCt remember, and Monday morni= ng >> laziness is strong today. Lars> Let's see... You didn't push it to the netsec branch, at least. = If you Lars> manage to find the patch, please do. I found the bottom half of the implementation, and just wrote the top half. I=CA=BCm wondering if 'network-lookup-address-info' should just return 5/9 element vectors like 'network-interface-info' (for IPv4/IPv6), so that remembering to chop the port off the end becomes unnecessary. Tested only on macOS so far. It covers the localhost case because 'network-interface-list' returns the loopback interface, which is true on my GNU/Linux box as well. If there=CA=BCs a platform where that=CA=BCs n= ot true we'll have to adjust the test. Robert 2019-07-29 Robert Pluim * lisp/net/nsm.el (nsm-network-same-subnet): New function. Checks if an ip address is in the same subnet as another one. (nsm-should-check): Use nsm-network-same-subnet to see if we're connecting to a local subnet machine. Remove checks for RFC1918 addresses. diff --git i/lisp/net/nsm.el w/lisp/net/nsm.el index b59ea07d8a..3adc1b1dc5 100644 --- i/lisp/net/nsm.el +++ w/lisp/net/nsm.el @@ -204,54 +204,52 @@ nsm-tls-post-check-functions RESULTS is an alist where the keys are the checks run and the values the results of the checks.") =20 +(defun nsm-network-same-subnet (local-ip mask ip) + "Returns t if IP is in the same subnet as LOCAL-IP/MASK. +LOCAL-IP, MASK, and IP are specified as vectors of integers, and +are expected to have the same length. Works for both IPv4 and +IPv6 addresses." + (let ((matches t) + (length (length local-ip))) + (unless (memq length '(4 5 8 9)) + (error "Unexpected length of IP address %S" local-ip)) + (dotimes (i length) + (setq matches (and matches + (=3D + (logand (aref local-ip i) + (aref mask i)) + (logand (aref ip i) + (aref mask i)))))) + matches)) + + (defun nsm-should-check (host) "Determines whether NSM should check for TLS problems for HOST. =20 If `nsm-trust-local-network' is or returns non-nil, and if the -host address is a localhost address, a machine address, a direct -link or a private network address, this function returns -nil. Non-nil otherwise." - (let* ((address (or (nslookup-host-ipv4 host nil 'vector) - (nslookup-host-ipv6 host nil 'vector))) - (ipv4? (eq (length address) 4))) - (not - (or (if ipv4? - (or - ;; (0.x.x.x) this machine - (eq (aref address 0) 0) - ;; (127.x.x.x) localhost - (eq (aref address 0) 0)) - (or - ;; (::) IPv6 this machine - (not (cl-mismatch address [0 0 0 0 0 0 0 0])) - ;; (::1) IPv6 localhost - (not (cl-mismatch address [0 0 0 0 0 0 0 1])))) - (and (or (and (functionp nsm-trust-local-network) - (funcall nsm-trust-local-network)) - nsm-trust-local-network) - (if ipv4? - (or - ;; (10.x.x.x) private - (eq (aref address 0) 10) - ;; (172.16.x.x) private - (and (eq (aref address 0) 172) - (eq (aref address 0) 16)) - ;; (192.168.x.x) private - (and (eq (aref address 0) 192) - (eq (aref address 0) 168)) - ;; (198.18.x.x) private - (and (eq (aref address 0) 198) - (eq (aref address 0) 18)) - ;; (169.254.x.x) link-local - (and (eq (aref address 0) 169) - (eq (aref address 0) 254))) - (memq (aref address 0) - '( - 64512 ;; (fc00::) IPv6 unique local address - 64768 ;; (fd00::) IPv6 unique local address - 65152 ;; (fe80::) IPv6 link-local - ) - ))))))) +host address is a localhost address, or in the same subnet as one +of the local interfaces, this function returns nil. Non-nil +otherwise." + (let ((addresses (network-lookup-address-info host)) + (network-interface-list (network-interface-list)) + (off-net t)) + (when + (or (and (functionp nsm-trust-local-network) + (funcall nsm-trust-local-network)) + nsm-trust-local-network) + (mapc + (lambda (address) + (mapc + (lambda (iface) + (let ((info (network-interface-info (car iface)))) + (when + (nsm-network-same-subnet (substring (car info) 0 -1) + (substring (car (cddr info)) 0 -= 1) + address) + (setq off-net nil)))) + network-interface-list)) + addresses)) + off-net)) =20 (defun nsm-check-tls-connection (process host port status settings) "Check TLS connection against potential security problems.