Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2365808ybi; Sun, 9 Jun 2019 09:59:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqwy5A25il3FFQ1GwLNB1dJ5SpWbxMO2d04Sj0bjgaM2J7ZcNcW1Q+TKmb3PrX0Wn9rbLY+J X-Received: by 2002:a17:90a:de08:: with SMTP id m8mr16840705pjv.50.1560099570160; Sun, 09 Jun 2019 09:59:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560099570; cv=none; d=google.com; s=arc-20160816; b=otAgLO5hqHI73/xX++gQ5LBqSXtluHqd5VACIUZ44yHBZHVFmpP/e+fNn5wZAS6ORB Shc9CybsDnu4rIa7xQZ2q9yX5R4Qkq4qD408dhgnMtO1RBrsZT1wkCbTvXAvSa7evI8K UiRWSHl5ZW/jUvOBhbz+hG9UOuotH3Ft8J0v4+aAUzm4MNxnv9uTIGts+MCvpXDafB/F xYZ/TT6nFdJ+gbFKgR7AVt44wDcm1vRG6VK11CyfVCG8lQsjAAiL2ShnyTzWIqD2Tlku 2QUb1ZwBBXhTHD8YubHpkDFPcz3dSB6S3WQN6oTNByyGC39pP1sW/wWsxA0dEYj51ybj Nmzw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=E5/0tcw1Tydp4Sd8J4iK5pGdYIemifPMREYnBZY8Wys=; b=TkAcw58iL73sIgXPoYR0CiR5dkWTEr0meXcSPRXPNmrR9hH7n90BUgBv7r7pueMPAE pn5YxMLZJXbz9tjkTCBxF3AcY2Naz2QZxAp3BtF1ajZRjfk5AjXIfo5Ub1JhhY07uRGM 1VUrFjBOj9v//FsiyXf++XIawVEg+zhcw0Z1tHrDnm5TXaWBBZiJs5Rl8pUjJE1OU/dP UayGdLfmmNwSsLATmZolnwr2jnQMyZFjsrpjH2wN++NPW0Rw+/tl2YVwy6el34TaKb+I aO8uBRrcK5T2q25gpCzgshM2wRrVJCfSHLNuTG91DiFUxQjNcyjRlbDtgU7Fw12/9Wda XLXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F2vZBBZV; 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 12si7624264pfh.109.2019.06.09.09.59.14; Sun, 09 Jun 2019 09:59:30 -0700 (PDT) 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; dkim=pass header.i=@kernel.org header.s=default header.b=F2vZBBZV; 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 S1733191AbfFIQ5b (ORCPT + 99 others); Sun, 9 Jun 2019 12:57:31 -0400 Received: from mail.kernel.org ([198.145.29.99]:60416 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732781AbfFIQ5Z (ORCPT ); Sun, 9 Jun 2019 12:57:25 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9FD53204EC; Sun, 9 Jun 2019 16:57:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560099445; bh=nC76t3TrHuK7vvzg/fKJuZBXGhPaAhvrXdQdM0tFHtk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F2vZBBZVFigbldNuApUAb+WhDLrroNvczBt0qmnjbRAIiEicl0u/obcNJsNbEZkPf xIs2RMLDhfzSuJYHGu6cGw0CmH7ry5fluKwcJNiZ1xxZkuLeeuF3PNhpM0/LtNiTvL l89ffLPjh6jmmAyLHgsGtS6yzVDXsk5HVeghwmZ0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Probst , Pavel Shilovsky , Steve French Subject: [PATCH 4.4 041/241] cifs: fix strcat buffer overflow and reduce raciness in smb21_set_oplock_level() Date: Sun, 9 Jun 2019 18:39:43 +0200 Message-Id: <20190609164148.958546130@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190609164147.729157653@linuxfoundation.org> References: <20190609164147.729157653@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christoph Probst commit 6a54b2e002c9d00b398d35724c79f9fe0d9b38fb upstream. Change strcat to strncpy in the "None" case to fix a buffer overflow when cinode->oplock is reset to 0 by another thread accessing the same cinode. It is never valid to append "None" to any other message. Consolidate multiple writes to cinode->oplock to reduce raciness. Signed-off-by: Christoph Probst Reviewed-by: Pavel Shilovsky Signed-off-by: Steve French CC: Stable Signed-off-by: Greg Kroah-Hartman --- fs/cifs/smb2ops.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) --- a/fs/cifs/smb2ops.c +++ b/fs/cifs/smb2ops.c @@ -1329,26 +1329,28 @@ smb21_set_oplock_level(struct cifsInodeI unsigned int epoch, bool *purge_cache) { char message[5] = {0}; + unsigned int new_oplock = 0; oplock &= 0xFF; if (oplock == SMB2_OPLOCK_LEVEL_NOCHANGE) return; - cinode->oplock = 0; if (oplock & SMB2_LEASE_READ_CACHING_HE) { - cinode->oplock |= CIFS_CACHE_READ_FLG; + new_oplock |= CIFS_CACHE_READ_FLG; strcat(message, "R"); } if (oplock & SMB2_LEASE_HANDLE_CACHING_HE) { - cinode->oplock |= CIFS_CACHE_HANDLE_FLG; + new_oplock |= CIFS_CACHE_HANDLE_FLG; strcat(message, "H"); } if (oplock & SMB2_LEASE_WRITE_CACHING_HE) { - cinode->oplock |= CIFS_CACHE_WRITE_FLG; + new_oplock |= CIFS_CACHE_WRITE_FLG; strcat(message, "W"); } - if (!cinode->oplock) - strcat(message, "None"); + if (!new_oplock) + strncpy(message, "None", sizeof(message)); + + cinode->oplock = new_oplock; cifs_dbg(FYI, "%s Lease granted on inode %p\n", message, &cinode->vfs_inode); }