public inbox for kernel-hardening@lists.openwall.com
 help / color / mirror / Atom feed
* [kernel-hardening] destroy unused shmem segments
@ 2011-06-13  6:42 Vasiliy Kulikov
  2011-06-13  7:07 ` Solar Designer
  0 siblings, 1 reply; 5+ messages in thread
From: Vasiliy Kulikov @ 2011-06-13  6:42 UTC (permalink / raw)
  To: kernel-hardening

Solar,

I'm looking into the -ow patch and I see this code:

	#ifdef CONFIG_HARDEN_SHM
	void shm_exit (void)
	{
		int i;
		struct shmid_kernel *shp;

		for (i = 0; i <= shm_ids.max_id; i++) {
			shp = shm_get(i);
			if (!shp) continue;

			if (shp->shm_cprid != current->pid) continue;

			if (shp->shm_nattch <= 0) {
				shp->shm_flags |= SHM_DEST;
				shm_destroy (shp);
			}
		}
	}
	#endif


	NORET_TYPE void do_exit(long code)
	{
		...
	#ifdef CONFIG_HARDEN_SHM
		shm_exit();
	#endif
		...
	}

However, the shm segment should be already freed by exit_mm() => vma->close():

	static struct vm_operations_struct shm_vm_ops = {
		open:	shm_open,	/* callback for a new vm-area open */
		close:	shm_close,	/* callback for when the vm-area is released */
		nopage:	shmem_nopage,
	};

	static void shm_close (struct vm_area_struct *shmd)
	{
		...
		shp->shm_nattch--;
	#ifdef CONFIG_HARDEN_SHM
		if(shp->shm_nattch == 0) {
			shp->shm_flags |= SHM_DEST;
			shm_destroy (shp);
		}
	#else
		if(shp->shm_nattch == 0 &&
		   shp->shm_flags & SHM_DEST)
			shm_destroy (shp);
	#endif
		...
	}

Is it some additional "safety" check or a workaround for some dubious
race?  I see no explicit need of such freeing cycle in do_exit().

Thanks,

-- 
Vasiliy

^ permalink raw reply	[flat|nested] 5+ messages in thread
* Re: [kernel-hardening] destroy unused shmem segments
@ 2011-06-14 17:51 Vasiliy Kulikov
  0 siblings, 0 replies; 5+ messages in thread
From: Vasiliy Kulikov @ 2011-06-14 17:51 UTC (permalink / raw)
  To: kernel-hardening

> +- shm_orphan_denied

> +shm_orphan_denied:

> +		.procname	= "shm_orphans_denied",

Oops, a typo.

Also maybe it should be named as "shm_forced_ipc_rmid" or just
"shm_forced_rmid"?  I dunno.

-- 
Vasiliy Kulikov

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-06-15 14:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-13  6:42 [kernel-hardening] destroy unused shmem segments Vasiliy Kulikov
2011-06-13  7:07 ` Solar Designer
2011-06-14  8:33   ` Vasiliy Kulikov
2011-06-15 14:42     ` Solar Designer
  -- strict thread matches above, loose matches on Subject: below --
2011-06-14 17:51 Vasiliy Kulikov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox