* Re: [PATCH] fs: namespace: convert mnt_namespace.count from atomic_t to refcount_t
[not found] <HK0PR01MB2163CC40FE7D44C73668C462ADD10@HK0PR01MB2163.apcprd01.prod.exchangelabs.com>
@ 2018-11-28 14:33 ` Al Viro
[not found] ` <HK0PR01MB21631393517B7937AF3FB55CADD20@HK0PR01MB2163.apcprd01.prod.exchangelabs.com>
0 siblings, 1 reply; 2+ messages in thread
From: Al Viro @ 2018-11-28 14:33 UTC (permalink / raw)
To: Yang Xiao; +Cc: linux-fsdevel
On Wed, Nov 28, 2018 at 07:30:10AM +0000, Yang Xiao wrote:
> From: Young Xiao <YangX92@hotmail.com>
>
> refcount_t type and corresponding API should be
^^^^^^
ITYM "could"
> used instead of atomic_t when the variable is used as
> a reference counter. This allows to avoid accidental
> refcounter overflows that might lead to use-after-free
> situations.
> static inline void get_mnt_ns(struct mnt_namespace *ns)
> {
> - atomic_inc(&ns->count);
> + if (ns)
> + refcount_inc(&ns->count);
> }
And this can be called with NULL ns... how, exactly?
> void put_mnt_ns(struct mnt_namespace *ns)
> {
> - if (!atomic_dec_and_test(&ns->count))
> + if (!ns || !refcount_dec_and_test(&ns->count))
> return;
Ditto. Incidentally, if you are into "defensive programming"
voodoo, how do you choose between checking for NULL and checking
for ERR_PTR(...)?
This kind of "just in case" stuff has its place, but it should
never be used mindlessly. NAK, unless you add a decent analysis
of the situation and a better rationale.
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] fs: namespace: convert mnt_namespace.count from atomic_t to refcount_t
[not found] ` <HK0PR01MB21631393517B7937AF3FB55CADD20@HK0PR01MB2163.apcprd01.prod.exchangelabs.com>
@ 2018-11-29 3:08 ` Al Viro
0 siblings, 0 replies; 2+ messages in thread
From: Al Viro @ 2018-11-29 3:08 UTC (permalink / raw)
To: Yang Xiao; +Cc: linux-fsdevel
On Thu, Nov 29, 2018 at 01:58:40AM +0000, Yang Xiao wrote:
> Hello, see commit 387ad9674b00 ("kernel: convert cgroup_namespace.count
> from atomic_t to refcount_t") for detail.
That would be
refcount_t type and corresponding API should be
used instead of atomic_t when the variable is used as
a reference counter. This allows to avoid accidental
refcounter overflows that might lead to use-after-free
situations.
AFAICS, that is the text you'd put into the original posting. Verbatim.
Which additional information have I failed to notice in the commit
you'd mentioned?
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-11-29 14:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <HK0PR01MB2163CC40FE7D44C73668C462ADD10@HK0PR01MB2163.apcprd01.prod.exchangelabs.com>
2018-11-28 14:33 ` [PATCH] fs: namespace: convert mnt_namespace.count from atomic_t to refcount_t Al Viro
[not found] ` <HK0PR01MB21631393517B7937AF3FB55CADD20@HK0PR01MB2163.apcprd01.prod.exchangelabs.com>
2018-11-29 3:08 ` Al Viro
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).