Received: by 10.223.185.116 with SMTP id b49csp1101636wrg; Fri, 23 Feb 2018 11:59:22 -0800 (PST) X-Google-Smtp-Source: AH8x227ZM8BkTWb2pWZnOI2O87iYX/8+1X9dYxb5gTx+KThRhZIR8pM34Xf+bbQOVJoG4Pms15N9 X-Received: by 10.98.75.129 with SMTP id d1mr1138033pfj.19.1519415962744; Fri, 23 Feb 2018 11:59:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519415962; cv=none; d=google.com; s=arc-20160816; b=twCHLP++hRVxXstpQCjlHSY2mkEuxoFTnmsOpr7caFdoPJevRvvJd/XkwM7OMkuQAB Do7mwnwq6hsbTvJGRLdvpWAtwDEmQrs1LgSNXBad42vSA31d9pF86xrxoqLaabdimLvL cPl9sviuGB99mqwSgYYJdtCRvokglPF5K4y1AW2CAF765ATBN3rks0SL1gt2RGoVxFff 8xR1SCsjKJrJZutXGA+auWFKUB3obBhQsRvGOHAZZNgHnqbPrLO7T3lUFqu4EFwoqcgq L+7kG+HEKXPTM8oJ+BbuzeNatOPxxmchTV69UmbFxumtNvTJhHNWjxGd7ii4AFPGet5L VVvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ovxd4J9vtVnX5kQldVxMrr0diccpDltU0JoH1IIvS4g=; b=zZT/kivfonFxVazeEvkgr0dzZHgsOASAPP/Kp5rShIFSI3eO8PTmgfU6R6CuhLoX+N PjoA6vb/aBpBQpYeyVLf4bXDnuN3M2Kn79rViCtkXmIlEayoOtax8LNdS3yBMB+3yatg tscp4thseWw7K4Y1sYIv9NApLVf0C0T/fwMQ8ZYzHwksQzQ22V8UTPBHgZTwn7pEyQZ9 17KDyjEPwX1AtfW3zBfTB1f1GdvHPHQQGMBxExrUjns1JJl+sYKSOGTiCb2SG5jJjTEk DEFz/apgp9OVu1P4ghM2EYWQNgTJFlHxzCIPAC6GqRlUXT6Dy2hhind2YUhd9puIvgC9 ++Aw== ARC-Authentication-Results: i=1; mx.google.com; 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 3-v6si2190867pls.721.2018.02.23.11.59.08; Fri, 23 Feb 2018 11:59:22 -0800 (PST) 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; 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 S933532AbeBWSoS (ORCPT + 99 others); Fri, 23 Feb 2018 13:44:18 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:42504 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932663AbeBWSoP (ORCPT ); Fri, 23 Feb 2018 13:44:15 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 0F38B122E; Fri, 23 Feb 2018 18:44:14 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+114b15f2be420a8886c3@syzkaller.appspotmail.com, Tom Herbert , Eric Dumazet , "David S. Miller" Subject: [PATCH 4.9 002/145] kcm: Check if sk_user_data already set in kcm_attach Date: Fri, 23 Feb 2018 19:25:08 +0100 Message-Id: <20180223170724.968449379@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170724.669759283@linuxfoundation.org> References: <20180223170724.669759283@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.9-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tom Herbert commit e5571240236c5652f3e079b1d5866716a7ad819c upstream. This is needed to prevent sk_user_data being overwritten. The check is done under the callback lock. This should prevent a socket from being attached twice to a KCM mux. It also prevents a socket from being attached for other use cases of sk_user_data as long as the other cases set sk_user_data under the lock. Followup work is needed to unify all the use cases of sk_user_data to use the same locking. Reported-by: syzbot+114b15f2be420a8886c3@syzkaller.appspotmail.com Fixes: ab7ac4eb9832 ("kcm: Kernel Connection Multiplexor module") Signed-off-by: Tom Herbert Reviewed-by: Eric Dumazet Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/kcm/kcmsock.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) --- a/net/kcm/kcmsock.c +++ b/net/kcm/kcmsock.c @@ -1404,9 +1404,18 @@ static int kcm_attach(struct socket *soc return err; } - sock_hold(csk); - write_lock_bh(&csk->sk_callback_lock); + + /* Check if sk_user_data is aready by KCM or someone else. + * Must be done under lock to prevent race conditions. + */ + if (csk->sk_user_data) { + write_unlock_bh(&csk->sk_callback_lock); + strp_done(&psock->strp); + kmem_cache_free(kcm_psockp, psock); + return -EALREADY; + } + psock->save_data_ready = csk->sk_data_ready; psock->save_write_space = csk->sk_write_space; psock->save_state_change = csk->sk_state_change; @@ -1414,8 +1423,11 @@ static int kcm_attach(struct socket *soc csk->sk_data_ready = psock_data_ready; csk->sk_write_space = psock_write_space; csk->sk_state_change = psock_state_change; + write_unlock_bh(&csk->sk_callback_lock); + sock_hold(csk); + /* Finished initialization, now add the psock to the MUX. */ spin_lock_bh(&mux->lock); head = &mux->psocks;