* [PATCH 0/3] s390 refcount conversions
@ 2017-10-20 7:47 Elena Reshetova
2017-10-20 7:47 ` [PATCH 1/3] [S390] vmur: convert urdev.ref_count from atomic_t to refcount_t Elena Reshetova
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Elena Reshetova @ 2017-10-20 7:47 UTC (permalink / raw)
To: linux-s390
Cc: linux-kernel, schwidefsky, heiko.carstens, jwi, ubraun, peterz,
keescook, Elena Reshetova
This series, for S390, replaces atomic_t reference
counters with the new refcount_t type and API (see include/linux/refcount.h).
By doing this we prevent intentional or accidental
underflows or overflows that can led to use-after-free vulnerabilities.
The patches are fully independent and can be cherry-picked separately.
Patches are based on top of linux-next as of yesterday.
If there are no objections to the patches, please merge them via respective trees
Elena Reshetova (3):
[S390] vmur: convert urdev.ref_count from atomic_t to refcount_t
[S390] net: convert lcs_reply.refcnt from atomic_t to refcount_t
[S390] qeth: convert qeth_reply.refcnt from atomic_t to refcount_t
drivers/s390/char/vmur.c | 8 ++++----
drivers/s390/char/vmur.h | 4 +++-
drivers/s390/net/lcs.c | 10 +++++-----
drivers/s390/net/lcs.h | 3 ++-
drivers/s390/net/qeth_core.h | 3 ++-
drivers/s390/net/qeth_core_main.c | 10 +++++-----
6 files changed, 21 insertions(+), 17 deletions(-)
--
2.7.4
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] [S390] vmur: convert urdev.ref_count from atomic_t to refcount_t
2017-10-20 7:47 [PATCH 0/3] s390 refcount conversions Elena Reshetova
@ 2017-10-20 7:47 ` Elena Reshetova
2017-10-26 6:34 ` Martin Schwidefsky
2017-10-20 7:47 ` [PATCH 2/3] [S390] net: convert lcs_reply.refcnt " Elena Reshetova
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Elena Reshetova @ 2017-10-20 7:47 UTC (permalink / raw)
To: linux-s390
Cc: linux-kernel, schwidefsky, heiko.carstens, jwi, ubraun, peterz,
keescook, Elena Reshetova
atomic_t variables are currently used to implement reference
counters with the following properties:
- counter is initialized to 1 using atomic_set()
- a resource is freed upon counter reaching zero
- once counter reaches zero, its further
increments aren't allowed
- counter schema uses basic atomic operations
(set, inc, inc_not_zero, dec_and_test, etc.)
Such atomic variables should be converted to a newly provided
refcount_t type and API that prevents accidental counter overflows
and underflows. This is important since overflows and underflows
can lead to use-after-free situation and be exploitable.
The variable urdev.ref_count is used as pure reference counter.
Convert it to refcount_t and fix up the operations.
Suggested-by: Kees Cook <keescook@chromium.org>
Reviewed-by: David Windsor <dwindsor@gmail.com>
Reviewed-by: Hans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
---
drivers/s390/char/vmur.c | 8 ++++----
drivers/s390/char/vmur.h | 4 +++-
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/s390/char/vmur.c b/drivers/s390/char/vmur.c
index 04aceb6..ced8151 100644
--- a/drivers/s390/char/vmur.c
+++ b/drivers/s390/char/vmur.c
@@ -110,7 +110,7 @@ static struct urdev *urdev_alloc(struct ccw_device *cdev)
mutex_init(&urd->io_mutex);
init_waitqueue_head(&urd->wait);
spin_lock_init(&urd->open_lock);
- atomic_set(&urd->ref_count, 1);
+ refcount_set(&urd->ref_count, 1);
urd->cdev = cdev;
get_device(&cdev->dev);
return urd;
@@ -126,7 +126,7 @@ static void urdev_free(struct urdev *urd)
static void urdev_get(struct urdev *urd)
{
- atomic_inc(&urd->ref_count);
+ refcount_inc(&urd->ref_count);
}
static struct urdev *urdev_get_from_cdev(struct ccw_device *cdev)
@@ -159,7 +159,7 @@ static struct urdev *urdev_get_from_devno(u16 devno)
static void urdev_put(struct urdev *urd)
{
- if (atomic_dec_and_test(&urd->ref_count))
+ if (refcount_dec_and_test(&urd->ref_count))
urdev_free(urd);
}
@@ -946,7 +946,7 @@ static int ur_set_offline_force(struct ccw_device *cdev, int force)
rc = -EBUSY;
goto fail_urdev_put;
}
- if (!force && (atomic_read(&urd->ref_count) > 2)) {
+ if (!force && (refcount_read(&urd->ref_count) > 2)) {
/* There is still a user of urd (e.g. ur_open) */
TRACE("ur_set_offline: BUSY\n");
rc = -EBUSY;
diff --git a/drivers/s390/char/vmur.h b/drivers/s390/char/vmur.h
index fa320ad..35ea9d1 100644
--- a/drivers/s390/char/vmur.h
+++ b/drivers/s390/char/vmur.h
@@ -11,6 +11,8 @@
#ifndef _VMUR_H_
#define _VMUR_H_
+#include <linux/refcount.h>
+
#define DEV_CLASS_UR_I 0x20 /* diag210 unit record input device class */
#define DEV_CLASS_UR_O 0x10 /* diag210 unit record output device class */
/*
@@ -69,7 +71,7 @@ struct urdev {
size_t reclen; /* Record length for *write* CCWs */
int class; /* VM device class */
int io_request_rc; /* return code from I/O request */
- atomic_t ref_count; /* reference counter */
+ refcount_t ref_count; /* reference counter */
wait_queue_head_t wait; /* wait queue to serialize open */
int open_flag; /* "urdev is open" flag */
spinlock_t open_lock; /* serialize critical sections */
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] [S390] net: convert lcs_reply.refcnt from atomic_t to refcount_t
2017-10-20 7:47 [PATCH 0/3] s390 refcount conversions Elena Reshetova
2017-10-20 7:47 ` [PATCH 1/3] [S390] vmur: convert urdev.ref_count from atomic_t to refcount_t Elena Reshetova
@ 2017-10-20 7:47 ` Elena Reshetova
2017-10-20 7:47 ` [PATCH 3/3] [S390] qeth: convert qeth_reply.refcnt " Elena Reshetova
2017-10-23 12:11 ` [PATCH 0/3] s390 refcount conversions Julian Wiedmann
3 siblings, 0 replies; 8+ messages in thread
From: Elena Reshetova @ 2017-10-20 7:47 UTC (permalink / raw)
To: linux-s390
Cc: linux-kernel, schwidefsky, heiko.carstens, jwi, ubraun, peterz,
keescook, Elena Reshetova
atomic_t variables are currently used to implement reference
counters with the following properties:
- counter is initialized to 1 using atomic_set()
- a resource is freed upon counter reaching zero
- once counter reaches zero, its further
increments aren't allowed
- counter schema uses basic atomic operations
(set, inc, inc_not_zero, dec_and_test, etc.)
Such atomic variables should be converted to a newly provided
refcount_t type and API that prevents accidental counter overflows
and underflows. This is important since overflows and underflows
can lead to use-after-free situation and be exploitable.
The variable lcs_reply.refcnt is used as pure reference counter.
Convert it to refcount_t and fix up the operations.
Suggested-by: Kees Cook <keescook@chromium.org>
Reviewed-by: David Windsor <dwindsor@gmail.com>
Reviewed-by: Hans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
---
drivers/s390/net/lcs.c | 10 +++++-----
drivers/s390/net/lcs.h | 3 ++-
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/s390/net/lcs.c b/drivers/s390/net/lcs.c
index d01b5c2..d7344be 100644
--- a/drivers/s390/net/lcs.c
+++ b/drivers/s390/net/lcs.c
@@ -769,15 +769,15 @@ lcs_get_lancmd(struct lcs_card *card, int count)
static void
lcs_get_reply(struct lcs_reply *reply)
{
- WARN_ON(atomic_read(&reply->refcnt) <= 0);
- atomic_inc(&reply->refcnt);
+ WARN_ON(refcount_read(&reply->refcnt) == 0);
+ refcount_inc(&reply->refcnt);
}
static void
lcs_put_reply(struct lcs_reply *reply)
{
- WARN_ON(atomic_read(&reply->refcnt) <= 0);
- if (atomic_dec_and_test(&reply->refcnt)) {
+ WARN_ON(refcount_read(&reply->refcnt) == 0);
+ if (refcount_dec_and_test(&reply->refcnt)) {
kfree(reply);
}
@@ -793,7 +793,7 @@ lcs_alloc_reply(struct lcs_cmd *cmd)
reply = kzalloc(sizeof(struct lcs_reply), GFP_ATOMIC);
if (!reply)
return NULL;
- atomic_set(&reply->refcnt,1);
+ refcount_set(&reply->refcnt,1);
reply->sequence_no = cmd->sequence_no;
reply->received = 0;
reply->rc = 0;
diff --git a/drivers/s390/net/lcs.h b/drivers/s390/net/lcs.h
index 150fcb4..3802f4f 100644
--- a/drivers/s390/net/lcs.h
+++ b/drivers/s390/net/lcs.h
@@ -4,6 +4,7 @@
#include <linux/netdevice.h>
#include <linux/skbuff.h>
#include <linux/workqueue.h>
+#include <linux/refcount.h>
#include <asm/ccwdev.h>
#define LCS_DBF_TEXT(level, name, text) \
@@ -270,7 +271,7 @@ struct lcs_buffer {
struct lcs_reply {
struct list_head list;
__u16 sequence_no;
- atomic_t refcnt;
+ refcount_t refcnt;
/* Callback for completion notification. */
void (*callback)(struct lcs_card *, struct lcs_cmd *);
wait_queue_head_t wait_q;
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] [S390] qeth: convert qeth_reply.refcnt from atomic_t to refcount_t
2017-10-20 7:47 [PATCH 0/3] s390 refcount conversions Elena Reshetova
2017-10-20 7:47 ` [PATCH 1/3] [S390] vmur: convert urdev.ref_count from atomic_t to refcount_t Elena Reshetova
2017-10-20 7:47 ` [PATCH 2/3] [S390] net: convert lcs_reply.refcnt " Elena Reshetova
@ 2017-10-20 7:47 ` Elena Reshetova
2017-10-23 12:11 ` [PATCH 0/3] s390 refcount conversions Julian Wiedmann
3 siblings, 0 replies; 8+ messages in thread
From: Elena Reshetova @ 2017-10-20 7:47 UTC (permalink / raw)
To: linux-s390
Cc: linux-kernel, schwidefsky, heiko.carstens, jwi, ubraun, peterz,
keescook, Elena Reshetova
atomic_t variables are currently used to implement reference
counters with the following properties:
- counter is initialized to 1 using atomic_set()
- a resource is freed upon counter reaching zero
- once counter reaches zero, its further
increments aren't allowed
- counter schema uses basic atomic operations
(set, inc, inc_not_zero, dec_and_test, etc.)
Such atomic variables should be converted to a newly provided
refcount_t type and API that prevents accidental counter overflows
and underflows. This is important since overflows and underflows
can lead to use-after-free situation and be exploitable.
The variable qeth_reply.refcnt is used as pure reference counter.
Convert it to refcount_t and fix up the operations.
Suggested-by: Kees Cook <keescook@chromium.org>
Reviewed-by: David Windsor <dwindsor@gmail.com>
Reviewed-by: Hans Liljestrand <ishkamiel@gmail.com>
Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
---
drivers/s390/net/qeth_core.h | 3 ++-
drivers/s390/net/qeth_core_main.c | 10 +++++-----
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/s390/net/qeth_core.h b/drivers/s390/net/qeth_core.h
index 91fcadb..49ba742 100644
--- a/drivers/s390/net/qeth_core.h
+++ b/drivers/s390/net/qeth_core.h
@@ -20,6 +20,7 @@
#include <linux/ethtool.h>
#include <linux/hashtable.h>
#include <linux/ip.h>
+#include <linux/refcount.h>
#include <net/ipv6.h>
#include <net/if_inet6.h>
@@ -645,7 +646,7 @@ struct qeth_reply {
int rc;
void *param;
struct qeth_card *card;
- atomic_t refcnt;
+ refcount_t refcnt;
};
struct qeth_card_blkt {
diff --git a/drivers/s390/net/qeth_core_main.c b/drivers/s390/net/qeth_core_main.c
index 68e118f..86e4c5d 100644
--- a/drivers/s390/net/qeth_core_main.c
+++ b/drivers/s390/net/qeth_core_main.c
@@ -559,7 +559,7 @@ static struct qeth_reply *qeth_alloc_reply(struct qeth_card *card)
reply = kzalloc(sizeof(struct qeth_reply), GFP_ATOMIC);
if (reply) {
- atomic_set(&reply->refcnt, 1);
+ refcount_set(&reply->refcnt, 1);
atomic_set(&reply->received, 0);
reply->card = card;
}
@@ -568,14 +568,14 @@ static struct qeth_reply *qeth_alloc_reply(struct qeth_card *card)
static void qeth_get_reply(struct qeth_reply *reply)
{
- WARN_ON(atomic_read(&reply->refcnt) <= 0);
- atomic_inc(&reply->refcnt);
+ WARN_ON(refcount_read(&reply->refcnt) == 0);
+ refcount_inc(&reply->refcnt);
}
static void qeth_put_reply(struct qeth_reply *reply)
{
- WARN_ON(atomic_read(&reply->refcnt) <= 0);
- if (atomic_dec_and_test(&reply->refcnt))
+ WARN_ON(refcount_read(&reply->refcnt) == 0);
+ if (refcount_dec_and_test(&reply->refcnt))
kfree(reply);
}
--
2.7.4
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 0/3] s390 refcount conversions
2017-10-20 7:47 [PATCH 0/3] s390 refcount conversions Elena Reshetova
` (2 preceding siblings ...)
2017-10-20 7:47 ` [PATCH 3/3] [S390] qeth: convert qeth_reply.refcnt " Elena Reshetova
@ 2017-10-23 12:11 ` Julian Wiedmann
2017-10-24 6:58 ` Reshetova, Elena
3 siblings, 1 reply; 8+ messages in thread
From: Julian Wiedmann @ 2017-10-23 12:11 UTC (permalink / raw)
To: Elena Reshetova, linux-s390
Cc: linux-kernel, schwidefsky, heiko.carstens, ubraun, peterz, keescook
On 10/20/2017 09:47 AM, Elena Reshetova wrote:
> This series, for S390, replaces atomic_t reference
> counters with the new refcount_t type and API (see include/linux/refcount.h).
> By doing this we prevent intentional or accidental
> underflows or overflows that can led to use-after-free vulnerabilities.
>
> The patches are fully independent and can be cherry-picked separately.
> Patches are based on top of linux-next as of yesterday.
> If there are no objections to the patches, please merge them via respective trees
>
> Elena Reshetova (3):
> [S390] vmur: convert urdev.ref_count from atomic_t to refcount_t
> [S390] net: convert lcs_reply.refcnt from atomic_t to refcount_t
> [S390] qeth: convert qeth_reply.refcnt from atomic_t to refcount_t
>
> drivers/s390/char/vmur.c | 8 ++++----
> drivers/s390/char/vmur.h | 4 +++-
> drivers/s390/net/lcs.c | 10 +++++-----
> drivers/s390/net/lcs.h | 3 ++-
> drivers/s390/net/qeth_core.h | 3 ++-
> drivers/s390/net/qeth_core_main.c | 10 +++++-----
> 6 files changed, 21 insertions(+), 17 deletions(-)
>
Thanks Elena, I picked up the two network patches. Also removed the WARN_ONs while applying,
those who care may use CONFIG_REFCOUNT_FULL.
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH 0/3] s390 refcount conversions
2017-10-23 12:11 ` [PATCH 0/3] s390 refcount conversions Julian Wiedmann
@ 2017-10-24 6:58 ` Reshetova, Elena
0 siblings, 0 replies; 8+ messages in thread
From: Reshetova, Elena @ 2017-10-24 6:58 UTC (permalink / raw)
To: Julian Wiedmann, linux-s390
Cc: linux-kernel, schwidefsky, heiko.carstens, ubraun, peterz, keescook
> On 10/20/2017 09:47 AM, Elena Reshetova wrote:
> > This series, for S390, replaces atomic_t reference
> > counters with the new refcount_t type and API (see include/linux/refcount.h).
> > By doing this we prevent intentional or accidental
> > underflows or overflows that can led to use-after-free vulnerabilities.
> >
> > The patches are fully independent and can be cherry-picked separately.
> > Patches are based on top of linux-next as of yesterday.
> > If there are no objections to the patches, please merge them via respective trees
> >
> > Elena Reshetova (3):
> > [S390] vmur: convert urdev.ref_count from atomic_t to refcount_t
> > [S390] net: convert lcs_reply.refcnt from atomic_t to refcount_t
> > [S390] qeth: convert qeth_reply.refcnt from atomic_t to refcount_t
> >
> > drivers/s390/char/vmur.c | 8 ++++----
> > drivers/s390/char/vmur.h | 4 +++-
> > drivers/s390/net/lcs.c | 10 +++++-----
> > drivers/s390/net/lcs.h | 3 ++-
> > drivers/s390/net/qeth_core.h | 3 ++-
> > drivers/s390/net/qeth_core_main.c | 10 +++++-----
> > 6 files changed, 21 insertions(+), 17 deletions(-)
> >
> Thanks Elena, I picked up the two network patches. Also removed the WARN_ONs
> while applying,
> those who care may use CONFIG_REFCOUNT_FULL.
Thank you Julian! I had them first removed also, but since we got x86 that doesn't
WARN in these cases, I put them back just to make sure I don't make any
unexpected changes.
Do you know who would be the correct person to take the last patch?
Best Regards,
Elena
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] [S390] vmur: convert urdev.ref_count from atomic_t to refcount_t
2017-10-20 7:47 ` [PATCH 1/3] [S390] vmur: convert urdev.ref_count from atomic_t to refcount_t Elena Reshetova
@ 2017-10-26 6:34 ` Martin Schwidefsky
2017-10-27 6:35 ` Reshetova, Elena
0 siblings, 1 reply; 8+ messages in thread
From: Martin Schwidefsky @ 2017-10-26 6:34 UTC (permalink / raw)
To: Elena Reshetova
Cc: linux-s390, linux-kernel, heiko.carstens, jwi, ubraun, peterz, keescook
On Fri, 20 Oct 2017 10:47:48 +0300
Elena Reshetova <elena.reshetova@intel.com> wrote:
> atomic_t variables are currently used to implement reference
> counters with the following properties:
> - counter is initialized to 1 using atomic_set()
> - a resource is freed upon counter reaching zero
> - once counter reaches zero, its further
> increments aren't allowed
> - counter schema uses basic atomic operations
> (set, inc, inc_not_zero, dec_and_test, etc.)
>
> Such atomic variables should be converted to a newly provided
> refcount_t type and API that prevents accidental counter overflows
> and underflows. This is important since overflows and underflows
> can lead to use-after-free situation and be exploitable.
>
> The variable urdev.ref_count is used as pure reference counter.
> Convert it to refcount_t and fix up the operations.
>
> Suggested-by: Kees Cook <keescook@chromium.org>
> Reviewed-by: David Windsor <dwindsor@gmail.com>
> Reviewed-by: Hans Liljestrand <ishkamiel@gmail.com>
> Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
Added to s390/linux:features for the next merge window. Thanks.
--
blue skies,
Martin.
"Reality continues to ruin my life." - Calvin.
^ permalink raw reply [flat|nested] 8+ messages in thread
* RE: [PATCH 1/3] [S390] vmur: convert urdev.ref_count from atomic_t to refcount_t
2017-10-26 6:34 ` Martin Schwidefsky
@ 2017-10-27 6:35 ` Reshetova, Elena
0 siblings, 0 replies; 8+ messages in thread
From: Reshetova, Elena @ 2017-10-27 6:35 UTC (permalink / raw)
To: Martin Schwidefsky
Cc: linux-s390, linux-kernel, heiko.carstens, jwi, ubraun, peterz, keescook
> On Fri, 20 Oct 2017 10:47:48 +0300
> Elena Reshetova <elena.reshetova@intel.com> wrote:
>
> > atomic_t variables are currently used to implement reference
> > counters with the following properties:
> > - counter is initialized to 1 using atomic_set()
> > - a resource is freed upon counter reaching zero
> > - once counter reaches zero, its further
> > increments aren't allowed
> > - counter schema uses basic atomic operations
> > (set, inc, inc_not_zero, dec_and_test, etc.)
> >
> > Such atomic variables should be converted to a newly provided
> > refcount_t type and API that prevents accidental counter overflows
> > and underflows. This is important since overflows and underflows
> > can lead to use-after-free situation and be exploitable.
> >
> > The variable urdev.ref_count is used as pure reference counter.
> > Convert it to refcount_t and fix up the operations.
> >
> > Suggested-by: Kees Cook <keescook@chromium.org>
> > Reviewed-by: David Windsor <dwindsor@gmail.com>
> > Reviewed-by: Hans Liljestrand <ishkamiel@gmail.com>
> > Signed-off-by: Elena Reshetova <elena.reshetova@intel.com>
>
> Added to s390/linux:features for the next merge window. Thanks.
Thank you very much!
Best Regards,
Elena.
>
> --
> blue skies,
> Martin.
>
> "Reality continues to ruin my life." - Calvin.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2017-10-27 6:35 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-20 7:47 [PATCH 0/3] s390 refcount conversions Elena Reshetova
2017-10-20 7:47 ` [PATCH 1/3] [S390] vmur: convert urdev.ref_count from atomic_t to refcount_t Elena Reshetova
2017-10-26 6:34 ` Martin Schwidefsky
2017-10-27 6:35 ` Reshetova, Elena
2017-10-20 7:47 ` [PATCH 2/3] [S390] net: convert lcs_reply.refcnt " Elena Reshetova
2017-10-20 7:47 ` [PATCH 3/3] [S390] qeth: convert qeth_reply.refcnt " Elena Reshetova
2017-10-23 12:11 ` [PATCH 0/3] s390 refcount conversions Julian Wiedmann
2017-10-24 6:58 ` Reshetova, Elena
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.