Received: by 10.213.65.68 with SMTP id h4csp161588imn; Thu, 15 Mar 2018 12:46:39 -0700 (PDT) X-Google-Smtp-Source: AG47ELsPkjBgcHTznUqyeQymJvzMSy183bFq/NAqJ6cIG8MZfY4/IVGBX1sL/6HE+gsfVJ7zEwRH X-Received: by 2002:a17:902:8287:: with SMTP id y7-v6mr9361311pln.85.1521143199450; Thu, 15 Mar 2018 12:46:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521143199; cv=none; d=google.com; s=arc-20160816; b=0ISE/u5lMzI5028600e2IzBqCj/o1RyL0gM50oe3kaG9EhrSjLzbvufdyHFt3m5zkw /O7ioZnPWLClXiSZUpv970HKuG4RXPJ8BNTyY4oIsDzlLyVkP6tYSsOGY+Yu19wf+28V sUs+19cbSEmjYtEYHdXHLo+fvC+y/n3zIPFuYPzJA8kQ7ZE1tdOES3shCKwG4kIARisH OocTsejUK6rmUCsj/71Ehss7SxofVGSPnCzcVdT3jTHj5TcOuWlAP9btu5CDoiDaYnaO we1aihDunkFVABkLluKUG08P/WWPp0AKy722mHJig5xTfZP/QBoyJ749COyisvPsbpdZ NnQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=GzXxmvX2jaaqnO7xgrgdJ0nlrpGVUszyXHCUWMQDfGc=; b=Se3YXZ5VjLwQN/0jCXIdljzNqTm71XkJDjeyJGcs5SBdhj3eTQs1PYvIh6Yj5DIsB0 PCtMReOLggB3l1sPiR8Eab9LYRaE1uJPsjQ45a0b/gZbsj0H2jUoimvH28ZbxDKfpJ3P ENIhEfMdVmd8zcz09N6/Ua3ye+fhYw3MRWYMwJGzwF2voYT17d7jJPpqFAl5LcdXtB1u CQBLZj8p4mCpndpWteibi9tD95aHf4A++ZQgZ0QqCe9SH8M9Es7LVkm0nOYe2ErVBBdx CORwobnS34kLWhZgd7NGzXY4N6r5bBOT0yfu9jhug/WSe7o1IqthODlAnsrSO/8lI8KH 9KOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Blwg/eUG; 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 n6si3834285pgc.801.2018.03.15.12.46.24; Thu, 15 Mar 2018 12:46:39 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=Blwg/eUG; 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 S1752337AbeCOTpc (ORCPT + 99 others); Thu, 15 Mar 2018 15:45:32 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:35920 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751394AbeCOTpa (ORCPT ); Thu, 15 Mar 2018 15:45:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=GzXxmvX2jaaqnO7xgrgdJ0nlrpGVUszyXHCUWMQDfGc=; b=Blwg/eUGmVNQnW2ZcGGa4ADj/ Nn/pOBO5C2cQdbUwJ8K+1mvjB9PraFRaz8UJgMQZzIT/6CdH1iWOueajpL5w7lCdWkjLqLYPYRzmT B8Uwsf/MDL0wOWaktTc1REaaskhzZ3aV5pO6auA1TRUQOlGuQI4bJquvzi8BTE2vOhmnP4CwqVoD3 lI4KwH4+h0VGP7wWB9rUL95qf/5y2nMPkmS3ckXOm4GvdpTLpAeETjY1e2N93Cp6zcoq+sygzgHPj yZLETHAQFa4ixY+Pf4sbWsEwEYVmFmEMqvg+tSxSztPJcXT0ax4lqrDm+mGh4t3Rm0r1hFSi8SY40 yJ0+lhF8g==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1ewYoZ-000697-8G; Thu, 15 Mar 2018 19:45:27 +0000 Date: Thu, 15 Mar 2018 12:45:27 -0700 From: Matthew Wilcox To: "Eric W. Biederman" Cc: Waiman Long , "Luis R. Rodriguez" , Kees Cook , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton , Al Viro , Stanislav Kinsbursky , Linux Containers Subject: Re: [RFC][PATCH] ipc: Remove IPCMNI Message-ID: <20180315194527.GB17574@bombadil.infradead.org> References: <1520885744-1546-1-git-send-email-longman@redhat.com> <1520885744-1546-5-git-send-email-longman@redhat.com> <87woyfyh57.fsf@xmission.com> <5d4a858a-3136-5ef4-76fe-a61e7f2aed56@redhat.com> <87o9jru3bf.fsf@xmission.com> <935a7c50-50cc-2dc0-33bb-92c000d039bc@redhat.com> <87woyego2u.fsf_-_@xmission.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87woyego2u.fsf_-_@xmission.com> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Mar 14, 2018 at 07:49:29PM -0500, Eric W. Biederman wrote: > @@ -109,20 +109,13 @@ void free_ipcs(struct ipc_namespace *ns, struct ipc_ids *ids, > { > struct kern_ipc_perm *perm; > int next_id; > - int total, in_use; > > down_write(&ids->rwsem); > - > - in_use = ids->in_use; > - > - for (total = 0, next_id = 0; total < in_use; next_id++) { > - perm = idr_find(&ids->ipcs_idr, next_id); > - if (perm == NULL) > - continue; > + next_id = 0; > + while ((perm = idr_get_next(&ids->ipcs_idr, &next_id))) { > rcu_read_lock(); > ipc_lock_object(perm); > free(ns, perm); > - total++; > } > up_write(&ids->rwsem); > } We have a helper for this: idr_for_each_entry(&ids->ipcs_idr, perm, next_id) { rcu_read_lock(); ipc_lock_object(perm); free(ns, perm); } (using idr_get_next() is tricky because you have to remember to increment next_id yourself, and you didn't). > +static int ipc_idr_alloc(struct ipc_ids *ids, struct kern_ipc_perm *new) > { > +#ifdef CONFIG_CHECKPOINT_RESTORE > + if (ids->next_id >= 0) { > + idr_set_cursor(&ids->ipcs_idr, ids->next_id); > ids->next_id = -1; > } > +#endif > + return idr_alloc_cyclic(&ids->ipcs_idr, (new), 0, 0, GFP_NOWAIT); > } > > -#endif /* CONFIG_CHECKPOINT_RESTORE */ That seems a little convoluted; is there a reason to not call idr_set_cursor() instead of assigning to ids->next_id? > @@ -757,30 +725,20 @@ static struct kern_ipc_perm *sysvipc_find_ipc(struct ipc_ids *ids, loff_t pos, > loff_t *new_pos) > { > struct kern_ipc_perm *ipc; > + int id; > > + /* Out of range - return NULL to terminate iteration */ > + if (pos > INT_MAX) > return NULL; > > + ipc = idr_get_next(&ids->ipcs_idr, &id); > + if (!ipc) > + return NULL; > > + *new_pos = id + 1; > + rcu_read_lock(); > + ipc_lock_object(ipc); > + return ipc; > } I'm no expert on the IPC locking, but I would have thought you'd want to call rcu_read_lock() before calling idr_get_next() to avoid a simultaneous delete from freeing 'ipc'. Oh, I see. proc_start takes the rwsem for read and proc_stop releases it. The locking here seems quite shabby and in need of renovation.