From patchwork Fri Dec 30 23:42:32 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Biggers X-Patchwork-Id: 9492565 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2DA7660488 for ; Fri, 30 Dec 2016 23:44:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D08B1FF65 for ; Fri, 30 Dec 2016 23:44:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11E8322701; Fri, 30 Dec 2016 23:44:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1A201FF65 for ; Fri, 30 Dec 2016 23:44:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754485AbcL3Xoq (ORCPT ); Fri, 30 Dec 2016 18:44:46 -0500 Received: from mail-it0-f65.google.com ([209.85.214.65]:35625 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754259AbcL3Xop (ORCPT ); Fri, 30 Dec 2016 18:44:45 -0500 Received: by mail-it0-f65.google.com with SMTP id b123so42914957itb.2; Fri, 30 Dec 2016 15:44:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=v8PDcjbcHFuXUD8GWkZpWtZO1rJxHEFwTJ5s60tqFsI=; b=qDo6feLPGVWPatYBEZO1QnIbaFz3XNzArV9pOJdtb46ubDT4IBXY2/GI22WdFrFDE5 NUvUgsMvc0EGW5goucRvaejyiNWZ6gCRgL9KICkR0WEOBdFBjKmM9lInjyCarBKO+JwX bMbaSIOnRX9oegHdU34hhdJMJVqeDRfHBusdGVh9g1vEa3jE9x1qTtTWS9VG1nz7YGjO SbSiNv65xTy8Rm+UPCsiO/sLxQOS+EEM/koXchlMCoRR9Z/aLVmeXtuSWLT1IKGxmolZ 1JfKJM7D4oujpIWYC2UU4rdifS9WOHFrbfsslO3DjHNdGB6kPYFmcmXaYhRJOfeKKkun nnPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=v8PDcjbcHFuXUD8GWkZpWtZO1rJxHEFwTJ5s60tqFsI=; b=sgOTGsB1Xi3g/OPj33L8njOXF6JjCrEYtmjB0QIgYF1n/t4cu7bvQNx8fhegcnbNX0 8Fx/VSrhCN73xpijGr0ZVjk2Zff5GeAh2mm5UqTadyH/Jz8TrYMDhoNHq+fqt/GtMhD8 gYW6hFYl9SHST779UNWt3InhO6/sP7KCcw8xLKJ2MNDcdAvVuTtyvw4ovKx+6ZeERLq+ XiywE4EvYxzaGNpR/6ZzNpitugzBa4o9b0pcOg9+hDIstMLx8JmMQafgZ5bW5oQSAduY SHbCgusL6bQCmpf7c7fUTx6fo7LGeuw3FZzAPVlh12tL2NDkcc6Ek7b5iNod79/6m7Rj L0KQ== X-Gm-Message-State: AIkVDXKEtcMS9WVo4a7hLTEfYP3VQITeN0E3Irmsqin+INe0aHQaFJYqr66j94DIlOyV2Q== X-Received: by 10.36.29.21 with SMTP id 21mr39429181itj.80.1483141484777; Fri, 30 Dec 2016 15:44:44 -0800 (PST) Received: from zzz.Home (h69-131-94-31.mdsnwi.broadband.dynamic.tds.net. [69.131.94.31]) by smtp.gmail.com with ESMTPSA id t129sm27787246iod.3.2016.12.30.15.44.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Dec 2016 15:44:44 -0800 (PST) From: Eric Biggers To: netdev@vger.kernel.org Cc: "David S. Miller" , Lorenzo Colitti , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Eric Biggers Subject: [PATCH] net: socket: don't set sk_uid to garbage value in ->setattr() Date: Fri, 30 Dec 2016 17:42:32 -0600 Message-Id: <20161230234232.4221-1-ebiggers3@gmail.com> X-Mailer: git-send-email 2.11.0 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Eric Biggers ->setattr() was recently implemented for socket files to sync the socket inode's uid to the new 'sk_uid' member of struct sock. It does this by copying over the ia_uid member of struct iattr. However, ia_uid is actually only valid when ATTR_UID is set in ia_valid, indicating that the uid is being changed, e.g. by chown. Other metadata operations such as chmod or utimes leave ia_uid uninitialized. Therefore, sk_uid could be set to a "garbage" value from the stack. Fix this by only copying the uid over when ATTR_UID is set. Fixes: 86741ec25462 ("net: core: Add a UID field to struct sock.") Signed-off-by: Eric Biggers Tested-by: Lorenzo Colitti Acked-by: Lorenzo Colitti --- net/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/socket.c b/net/socket.c index 8487bf136e5c..a8c2307590b8 100644 --- a/net/socket.c +++ b/net/socket.c @@ -537,7 +537,7 @@ int sockfs_setattr(struct dentry *dentry, struct iattr *iattr) { int err = simple_setattr(dentry, iattr); - if (!err) { + if (!err && (iattr->ia_valid & ATTR_UID)) { struct socket *sock = SOCKET_I(d_inode(dentry)); sock->sk->sk_uid = iattr->ia_uid;