From patchwork Mon Dec 13 16:08:36 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Shilovsky X-Patchwork-Id: 407062 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 oBDGEPnX025114 for ; Mon, 13 Dec 2010 16:14:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757735Ab0LMQOZ (ORCPT ); Mon, 13 Dec 2010 11:14:25 -0500 Received: from mail-ey0-f171.google.com ([209.85.215.171]:33522 "EHLO mail-ey0-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757595Ab0LMQOY (ORCPT ); Mon, 13 Dec 2010 11:14:24 -0500 Received: by eyg5 with SMTP id 5so4273374eyg.2 for ; Mon, 13 Dec 2010 08:14:23 -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=VjLHFplhKxWm2/8g7W7zZ1qB8A+qIr9B7XwN+KY4+Mg=; b=dKc3Gu3QpkvxTSsdWfhmWN9ybGAcXQiN9dJJiKbARYFnLGvDSYXP49Fq/7RPn5f9NT RgpB9L3hYXjWVLAvaiF+jJQzRpkPiBP22KYr3OzwTiM8szbswy0ioxI6uj/Le9Sp6nR2 S93Sp4ZitzNdxiy6OR81mCrxD2mPJYhnPhHmo= 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=WgUVVAkVUktDP4aUvBxobObvkeBsz3nB5AKmwdjX2lzM83AdQBlg9z9dnH0EsnEDLy r0FQZ20MXyzWvQiktltq+Z5h2vqbuMQX1SzTNBT8W7cF+uJ+z1U0D/utF0EA0cZOS9mo TSDy8qniMXA5xP8VuHq3yZ7M5kKfb3SgSaEJw= Received: by 10.213.16.140 with SMTP id o12mr955919eba.29.1292256539887; Mon, 13 Dec 2010 08:08:59 -0800 (PST) Received: from localhost.localdomain (PPPoE-78-29-112-8.san.ru [78.29.112.8]) by mx.google.com with ESMTPS id x54sm187240eeh.11.2010.12.13.08.08.57 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 13 Dec 2010 08:08:59 -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 (try #3) Date: Mon, 13 Dec 2010 19:08:36 +0300 Message-Id: <1292256516-4343-2-git-send-email-piastryyy@gmail.com> X-Mailer: git-send-email 1.7.3.2 In-Reply-To: <1292256516-4343-1-git-send-email-piastryyy@gmail.com> References: <1292256516-4343-1-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]); Mon, 13 Dec 2010 16:14:25 +0000 (UTC) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index b90c741..b9b0ad5 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -1453,6 +1453,39 @@ srcip_matches(struct sockaddr *srcaddr, struct sockaddr *rhs) } } +/* + * If no port is specified in addr structure, we try to match with 445 port + * and if it fails - with 139 ports + */ +static bool +match_port(struct TCP_Server_Info *server, struct sockaddr *addr) +{ + unsigned short int port, *sport; + + switch (addr->sa_family) { + case AF_INET: + sport = &((struct sockaddr_in *) &server->dstaddr)->sin_port; + port = ((struct sockaddr_in *) addr)->sin_port; + break; + case AF_INET6: + sport = &((struct sockaddr_in6 *) &server->dstaddr)->sin6_port; + port = ((struct sockaddr_in6 *) addr)->sin6_port; + break; + default: + WARN_ON(1); + return false; + } + + if (!port) { + port = htons(CIFS_PORT); + if (port == *sport) + return true; + + port = htons(RFC1001_PORT); + } + + return port == *sport; +} static bool match_address(struct TCP_Server_Info *server, struct sockaddr *addr, @@ -1466,8 +1499,6 @@ match_address(struct TCP_Server_Info *server, struct sockaddr *addr, if (addr4->sin_addr.s_addr != srv_addr4->sin_addr.s_addr) return false; - if (addr4->sin_port && addr4->sin_port != srv_addr4->sin_port) - return false; break; } case AF_INET6: { @@ -1480,9 +1511,6 @@ match_address(struct TCP_Server_Info *server, struct sockaddr *addr, return false; if (addr6->sin6_scope_id != srv_addr6->sin6_scope_id) return false; - if (addr6->sin6_port && - addr6->sin6_port != srv_addr6->sin6_port) - return false; break; } default: @@ -1555,6 +1583,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;