NetBSD Problem Report #54992
From ryo@moveq.nerv.org Thu Feb 20 21:04:14 2020
Return-Path: <ryo@moveq.nerv.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
by mollari.NetBSD.org (Postfix) with ESMTPS id 283DB1A9213
for <gnats-bugs@gnats.NetBSD.org>; Thu, 20 Feb 2020 21:04:14 +0000 (UTC)
Message-Id: <20200220191410.7F51614B07A@moveq.nerv.org>
Date: Fri, 21 Feb 2020 04:14:10 +0900 (JST)
From: ryo@nerv.org
Reply-To: ryo@nerv.org
To: gnats-bugs@NetBSD.org
Subject: hosts_access(5) doesn't work for IPv6 linklocal address without scope-id
X-Send-Pr-Version: 3.95
>Number: 54992
>Category: lib
>Synopsis: hosts_access(5) doesn't work for IPv6 linklocal address without scope-id
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: ryo
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Feb 20 21:05:00 +0000 2020
>Closed-Date: Mon Mar 30 08:37:51 +0000 2020
>Last-Modified: Mon Mar 30 08:37:51 +0000 2020
>Originator: Ryo Shimizu
>Release: NetBSD 9.99.46
>Organization:
>Environment:
System: NetBSD subq 9.99.46 NetBSD 9.99.46 (SUBQ) #17: Mon Feb 10 02:58:24 JST 2020 ryo@subq:/usr/src/sys/arch/amd64/compile/SUBQ amd64
Architecture: x86_64
Machine: amd64
>Description:
[hosts.allow]
ALL: [fe80::%re0/16] # this works
but,
[hosts.allow]
ALL: [fe80::/16] # this doesn't work.
>How-To-Repeat:
hostA# echo 'ALL: [fe80::/16]' >> /etc/hosts.allow
hostB# ssh fe80::6d9:f5ff:fe06:e273%wm2
connect to linklocal address of hostA, but connection refused.
>Fix:
In this case, it should be compared only addresses, with or without scope-id.
libwrap/hosts_access.c:masked_match6() always compares scope_id when the address is linklocal.
(e.g., string="fe80::1efd:8ff:fe70:5d2e%re0", net="fe80::", mask="16")
> if (addr.sa.sa_family == AF_INET6 && addr.sin6.sin6_scope_id &&
> addr.sin6.sin6_scope_id != net.sin6.sin6_scope_id)
> return NO;
'addr' is a client address extracted by getaddrinfo() from 'string' argument,
and 'net' is address/mask written in /etc/hosts.{allow,deny}.
when addr is a linklocal, the 2nd condition (addr.sin6.sin6_scope_id) is true, but
'net' may not have valid scope-id, therefore
if (addr.sa.sa_family == AF_INET6 && addr.sin6.sin6_scope_id && net.sin6.sin6_scope_id &&
addr.sin6.sin6_scope_id != net.sin6.sin6_scope_id)
return NO;
However, this is too verbose, so the following is sufficient.
Index: hosts_access.c
===================================================================
RCS file: /src/cvs/cvsroot-netbsd/src/lib/libwrap/hosts_access.c,v
retrieving revision 1.21
diff -a -u -r1.21 hosts_access.c
--- hosts_access.c 17 Feb 2016 19:52:20 -0000 1.21
+++ hosts_access.c 19 Feb 2020 18:01:24 -0000
@@ -561,7 +561,7 @@
for (i = 0; i < alen; i++)
ap[i] &= mp[i];
- if (addr.sa.sa_family == AF_INET6 && addr.sin6.sin6_scope_id &&
+ if (addr.sa.sa_family == AF_INET6 && net.sin6.sin6_scope_id &&
addr.sin6.sin6_scope_id != net.sin6.sin6_scope_id)
return NO;
return (memcmp(ap, np, alen) == 0);
>Release-Note:
>Audit-Trail:
From: "Ryo Shimizu" <ryo@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:
Subject: PR/54992 CVS commit: src/lib/libwrap
Date: Mon, 30 Mar 2020 08:34:39 +0000
Module Name: src
Committed By: ryo
Date: Mon Mar 30 08:34:38 UTC 2020
Modified Files:
src/lib/libwrap: hosts_access.c
Log Message:
PR/54992: fix hosts_access(5) to works for IPv6 linklocal address without scope-id
To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libwrap/hosts_access.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Responsible-Changed-From-To: lib-bug-people->ryo
Responsible-Changed-By: ryo@NetBSD.org
Responsible-Changed-When: Mon, 30 Mar 2020 08:37:51 +0000
Responsible-Changed-Why:
mime
State-Changed-From-To: open->closed
State-Changed-By: ryo@NetBSD.org
State-Changed-When: Mon, 30 Mar 2020 08:37:51 +0000
State-Changed-Why:
fixed
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.46 2020/01/03 16:35:01 leot Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2020
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.