From patchwork Sun Nov 14 18:49:09 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 323782 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oAEIn99k012468 for ; Sun, 14 Nov 2010 18:49:28 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756827Ab0KNSt1 (ORCPT ); Sun, 14 Nov 2010 13:49:27 -0500 Received: from mail-ew0-f46.google.com ([209.85.215.46]:41561 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756779Ab0KNSt1 (ORCPT ); Sun, 14 Nov 2010 13:49:27 -0500 Received: by ewy8 with SMTP id 8so426766ewy.19 for ; Sun, 14 Nov 2010 10:49:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :message-id:x-mailer:in-reply-to:references; bh=iloaXpM3dmBp39xtdnI0ygYgXNnORimFuZCEess0CIM=; b=SqVy21ELjwgs35duw27CIJrbS80vjUeOULmhfKnGZ6wvtqNbtY1Q1R0TN9gw4aw3DT RDPxF9Nevgh8cPFsL8qHhBnOsntTHrrIQXgPuCcnLzhhKIkcbiLOpZl9YfswWFrQcelP 0uESttRCkWkz2S4AR7C6EJiR+EkH11a2OP+lo= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; b=hacGjUF89a1hxoazQqEnEUQ8BLuCQLw0HE0eI182aTvAvb1BtmctWlytu6zKKrTXfT KE79R9aa9KItKRp9QzSrNtMEW0WJXUyEhJl0H9uUCRtMrMVqJmHtWVOcL7/apJuH8qHf sfvlG9zRDAWGjGEFvcplV4AZP3BHMVx4jK5QM= Received: by 10.14.119.198 with SMTP id n46mr3119881eeh.38.1289760566237; Sun, 14 Nov 2010 10:49:26 -0800 (PST) Received: from localhost.localdomain (PPPoE-78-29-93-156.san.ru [78.29.93.156]) by mx.google.com with ESMTPS id w20sm5741389eeh.18.2010.11.14.10.49.24 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 14 Nov 2010 10:49:25 -0800 (PST) From: Pavel Shilovsky To: linux-cifs@vger.kernel.org Subject: [PATCH 2/2] CIFS: Add match_port check during looking for an existing connection Date: Sun, 14 Nov 2010 21:49:09 +0300 Message-Id: <1289760549-8760-1-git-send-email-piastryyy@gmail.com> X-Mailer: git-send-email 1.7.3.2 In-Reply-To: <1289734155-3613-2-git-send-email-piastryyy@gmail.com> References: <1289734155-3613-2-git-send-email-piastryyy@gmail.com> Sender: linux-cifs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-cifs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Sun, 14 Nov 2010 18:49:28 +0000 (UTC) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index 01ebcc4..7130dd7 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -1435,6 +1435,34 @@ srcip_matches(struct sockaddr *srcaddr, struct sockaddr *rhs) } } +static bool +match_port(struct TCP_Server_Info *server, struct sockaddr *addr) +{ + struct sockaddr_in *addr4 = (struct sockaddr_in *)addr; + struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr; + unsigned short int port; + + /* search for a connection with the default port if user doesn't + specify the port manually */ + port = htons(CIFS_PORT); + + switch (addr->sa_family) { + case AF_INET: + if (addr4->sin_port) + port = addr4->sin_port; + if (port != server->addr.sockAddr.sin_port) + return false; + break; + case AF_INET6: + if (addr6->sin6_port) + port = addr6->sin6_port; + if (port != server->addr.sockAddr6.sin6_port) + return false; + break; + } + + return true; +} static bool match_address(struct TCP_Server_Info *server, struct sockaddr *addr, @@ -1448,9 +1476,6 @@ match_address(struct TCP_Server_Info *server, struct sockaddr *addr, if (addr4->sin_addr.s_addr != server->addr.sockAddr.sin_addr.s_addr) return false; - if (addr4->sin_port && - addr4->sin_port != server->addr.sockAddr.sin_port) - return false; break; case AF_INET6: if (!ipv6_addr_equal(&addr6->sin6_addr, @@ -1459,9 +1484,6 @@ match_address(struct TCP_Server_Info *server, struct sockaddr *addr, if (addr6->sin6_scope_id != server->addr.sockAddr6.sin6_scope_id) return false; - if (addr6->sin6_port && - addr6->sin6_port != server->addr.sockAddr6.sin6_port) - return false; break; } @@ -1530,6 +1552,9 @@ cifs_find_tcp_session(struct sockaddr *addr, struct smb_vol *vol) (struct sockaddr *)&vol->srcaddr)) continue; + if (!match_port(server, addr)) + continue; + if (!match_security(server, vol)) continue;